我正在尝试使用easyXdm库获取跨域AJAX帖子。
在我的本地开发环境中,我有两个站点:
1. http://localhost/MySite/ws/easyXDM/cors/index.html (EasyXdm file) 2. http://localhost/MyClientSite/TestPage.html (AJAX post from here)
TestPage.html(AJAX Post)
var rpc = new easyXDM.Rpc({
remote: "http://localhost/MySite/ws/easyXDM/cors/index.html"
},
{
remote: {
request: {}
}
});
rpc.request({
url: "http://localhost/MySite/ws/MyService.asmx/DoSomething",
method: "POST",
data: jsonData
}, function(response) {
console.log(JSON.parse(response.data));
$('#thanksDiv').fadeIn(2000, function () {
$('#thanksDiv').fadeOut(4000);
});
});
当我执行AJAX帖子时,我在浏览器的控制台中获得以下内容:
easyXDM present on 'http://localhost/MySite/ws/easyXDM/cors/index.html?xdm_e=http%3A%2F%2Flocalhost%2FMyClientSite%2FTestPage.html&xdm_c=default884&xdm_p=4
native JSON found
easyXDM.Rpc: constructor
{Private}: preparing transport stack
{Private}: using parameters from query
easyXDM.stack.SameOriginTransport: constructor
easyXDM.stack.QueueBehavior: constructor
easyXDM.stack.RpcBehavior: init
{Private}: firing dom_onReady
... deferred messages ...
easyXDM.Rpc: constructor
{Private}: preparing transport stack
{Private}: using parameters from query
easyXDM.stack.SameOriginTransport: constructor
easyXDM.stack.QueueBehavior: constructor
easyXDM.stack.RpcBehavior: init
... end of deferred messages ...
easyXDM.stack.SameOriginTransport: init
easyXDM.stack.RpcBehavior: received request to execute method request using callback id 1
easyXDM.stack.RpcBehavior: requested to execute procedure request
easyXDM.stack.QueueBehavior: removing myself from the stack
问题: Web服务实际上从未接收过数据。这很明显,因为我的AJAX后期成功函数应显示thanksDiv
,并且还应在*数据库中创建记录。
注意:我正在替换现有的AJAX邮政编码,因为我需要使用easyXdm来解决客户网站上Internet Explorer 6和7的问题。
其他信息: 我的easyXdm文件所在的文件结构如下:
/ws/easyXDM/easyXDM.debug.js
/ws/easyXDM/easyXdm.swf
/ws/easyXDM/json2.js
/ws/easyXDM/name.html
/ws/easyXDM/cors/index.html
答案 0 :(得分:1)
我的网络服务因为没有通过easyXdm正确发送jsonData而抛出HTTP 500服务器错误。
json数据在发布之前看起来像这样:
{“param1”:“value1”,“param2”:“value2”......}
但是,Web服务每行接收一个字符数据,例如
{
"
p
a
r
a
m
"
....
我没有在发布之前将json数据序列化。所以,基于我在原始问题中发布的原始代码:
为了让它正常工作,我改变了行
data: jsonData
到
data: JSON.parse(jsonData)