2013-03-27 108 views
3

我想獲得跨域AJAX後使用easyXdm庫工作。使用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郵報)

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

存在已經與easyXDM工作這麼幾個人。你可以看看http://stackoverflow.com/questions/27203172/easyxdm-download-files-from-3rd-party-service嗎? – 2014-11-29 22:35:48

+0

@V_B客戶端和服務器都必須使用EasyXDM才能成功運行。 – Seany84 2014-11-30 13:57:53

回答

1

我的Web服務被扔一個HTTP 500服務器錯誤爲jsonData不能被正確地通過easyXdm發送。

JSON數據看起來像這樣它被張貼之前:

{ 「參數1」: 「值1」, 「參數2」: 「值2」 ......}

但是,Web服務每行接收一個字符的數據,例如

{ 
" 
p 
a 
r 
a 
m 
" 
.... 

我沒有序列化JSON數據之前,我的職位。因此,在原有基礎上的代碼,我貼在原來的問題:

得到它的工作我改了行

data: jsonData 

data: JSON.parse(jsonData)