简体   繁体   English

Sencha touch 2无法让Ajax调用工作

[英]Sencha touch 2 cannot get Ajax calls working

I have this simple function which I call from my applications launch() function: 我有这个简单的函数,我从我的应用程序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
    }
  });
}

The problem is that this request doesn't seem to get made. 问题是这个请求似乎没有得到。 It doesn't show up on my Play framework server or in Google Chrome's network developer tab. 它不会显示在我的Play框架服务器或Google Chrome的网络开发人员标签中。

EDIT Program also seems to get stuck to the Ext.Ajax.request function. 编辑程序似乎也陷入了Ext.Ajax.request函数。

The Following Code for ajax calling working well for me. 以下代码为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");
    }
});

Your url should be a http url. 你的网址应该是一个http网址。 You should also specify the action (GET, POST) for example. 您还应该指定操作(GET,POST)。 You already specified that you want to do an ajax call by using Ext.Ajax.request. 您已经指定要使用Ext.Ajax.request进行ajax调用。

If you want to use parameters, use a parameter object. 如果要使用参数,请使用参数对象。

example: 例:

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

Check the network tab in your chrome developer tools if the request has been made. 如果已提出请求,请检查chrome开发人员工具中的网络选项卡。

I noticed that I forgot to add the Ext.Ajax to my applications requires field. 我注意到我忘了将Ext.Ajax添加到我的应用程序需求字段中。 After adding it everything works just fine. 添加后,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM