sencha touch《實現ajax跨域請求》

【環境說明】

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


【截圖演示】






發佈了29 篇原創文章 · 獲贊 18 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章