【环境说明】
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); } }
【截图演示】
原文链接:https://www.f2er.com/ajax/165233.html