您的位置:首页 > 其它

sencha touch《实现ajax跨域请求》

2014-02-25 11:44 375 查看
【环境说明】

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);
}
}


【截图演示】



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sencha touch ajax CORS play