加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sencha touch《实现ajax跨域请求》

发布时间:2020-12-16 00:40:59 所属栏目:百科 来源:网络整理
导读:【环境说明】 1、sencha touch : 2.3.1 2、play : 2.2.0 3、chrome 【代码示例】 1、sencha touch Ext.Ajax.request({ url:'http://10.228.190.97:9000/login'+"/"+userName+"/"+password,useDefaultXhrHeader : false,success: function(result,request) {

【环境说明】

1、sencha touch : 2.3.1

2、play : 2.2.0

3、chrome

【代码示例】

1、sencha touch

 Ext.Ajax.request({
        url:'http://10.228.190.97:9000/login'+"/"+userName+"/"+password,useDefaultXhrHeader : false,success: function(result,request) {
            var respText =  Ext.JSON.decode(result.responseText); 
            alert(respText.email);
        }
    });

2.1、play --UserController.java

@With(CorsAction.class)
public class UserController extends Controller{
   @Transactional
   public static Result login(String _dc,String username,String userpwd) {
     Contact contact = Contact.login(username,userpwd);
     return ok(parser(contact));
   }
}

2.2、play --CorsAction.java
public class CorsAction extends Action.Simple {
    public Promise<SimpleResult> call(Context context) throws Throwable{
        Response response = context.response();
        response.setHeader("Access-Control-Allow-Origin","*");
        response.setHeader("Access-Control-Allow-Headers","X-Requested-With");
        return delegate.call(context);
    }
}


【截图演示】



(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读