加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

跨域Ajax与Ext.Ajax.request

发布时间:2020-12-16 02:49:47 所属栏目:百科 来源:网络整理
导读:看来我无法使用Ext.Ajax.request进行跨域ajax调用.看起来像ScriptTag:True没有任何效果. 这是我的代码: { xtype: 'button',text: 'Search',ui: 'confirm',handler: function() { var query = Ext.getCmp("textquery").getValue(); Ext.Ajax.request({ url:
看来我无法使用Ext.Ajax.request进行跨域ajax调用.看起来像ScriptTag:True没有任何效果.

这是我的代码:

{
            xtype: 'button',text: 'Search',ui: 'confirm',handler: function() {
                var query = Ext.getCmp("textquery").getValue();
                Ext.Ajax.request({
                    url: 'http://example.com/?search='+query,dataType: 'jsonp',jsonp: 'jsonp_callback',scriptTag: true,success: function(e) {
                        var obj = Ext.decode(e.responseText);
                        var msg = obj;
                        var html = tpl.apply(msg);
                        resultPanel.update(html);
                    }
                });
            }

控制台日志告诉我:

XMLHttpRequest cannot load http://example.com/?search=test&_dc=1326551713063. Origin http://myapp.lo is not allowed by Access-Control-Allow-Origin.

使用jquery我做了同样的事情并且它有效,但我必须使用sencha touch.

var formData = $("#callAjaxForm").serialize();

              $.ajax({
                url:"http://example.com/leksikonapi/",data: formData,success: onSuccess,error: onError
              });

我看不出两者之间有什么不同.

解决方法

尝试使用 Ext.util.JSONP.我没有看到使用Ext.Ajax在文档中执行jsonp的方法

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读