gpt4 book ai didi

ajax - 使用 Ext.Ajax.request 的跨域 Ajax

转载 作者:行者123 更新时间:2023-12-05 00:01:48 28 4
gpt4 key购买 nike

似乎我无法使用 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/",
dataType: 'jsonp',
jsonp: 'jsonp_callback',
data: formData,
success: onSuccess,
error: onError
});

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

最佳答案

Sencha Touch 2 的解决方案:使用 Ext.data.JsonP
http://docs.sencha.com/touch/2-1/#!/api/Ext.data.JsonP

关于ajax - 使用 Ext.Ajax.request 的跨域 Ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8863261/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com