Sencha touch 2无法让Ajax调用工作

时间:2014-03-16 14:29:03

标签: javascript ajax http sencha-touch sencha-touch-2

我有这个简单的函数,我从我的应用程序launch()函数调用:

function ajaxCall(){
  Ext.Ajax.request({
    url: 'ajax/Hello!', // Request should go to host/ajax url as http get request
                 // and server should return plain text `Hello!` as answer
    success: function(response){
      prompt('Ajax call success!', response.responseText); // My own prompting method
    }
  });
}

问题是这个请求似乎没有成功。它不会出现在我的Play框架服务器或Google Chrome的网络开发人员标签中。

修改 程序似乎也陷入了Ext.Ajax.request函数。

3 个答案:

答案 0 :(得分:2)

以下的ajax调用代码对我来说运作良好。

Ext.Ajax.request({
    async : true,
    url : 'api/login/',
    method : 'POST',
    jsonData : {
        "email":Ext.getCmp('loginUserNameTxtBoxId')._value,
        "pwd":Ext.getCmp('loginPasswordTxtBoxId')._value,
    },
    success : function (request, resp) {
        alert("in login success");
    },
    failure: function(request, resp) {
        alert("in failure");
    }
});

答案 1 :(得分:1)

您的网址应该是http网址。您还应该指定操作(GET,POST)。您已经指定要使用Ext.Ajax.request进行ajax调用。

如果要使用参数,请使用参数对象。

示例:

 Ext.Ajax.request({
        url : 'http://google.com/api/blabla',
        method: 'GET',
        params: {
            username: 'bla',
            password: 'blabla'
        },
        success: function(response, request) { console.log('success'); }
    });  

如果已提出请求,请检查Chrome开发者工具中的网络标签。

答案 2 :(得分:0)

我注意到我忘记将Ext.Ajax添加到我的应用程序需求字段中。添加后,一切正常。