2014-01-21 109 views
2

我從外部域對Web服務進行了AJAX調用,並試圖管理XML響應,因爲AJAX調用的目標是在Adobe Connect平臺上登錄並且它作品。但它顯示的瀏覽器控制檯下面的錯誤上:使用XML響應的AJAX JQuery請求

SyntaxError: syntax error 
<?xml version="1.0" encoding="utf-8"?> 

這是AJAX調用的代碼:

$.ajax({ 
type : "GET", 
    url : URL, 
    dataType : "jsonp", 
    success : function(service_data) { 
    console.log("OK"); 
    console.log(service_data); 
    }, 
    error : function(msg) { 
    console.log("ERROR"); 
    console.log(JSON.stringify(msg)); 
    } 
}); 

萬分感謝。

+1

可以說明你的問題?我的意思是,你的電話有效,但有錯誤? –

+2

原始'XML'看起來像什麼? – JNF

+2

確切地說,它的工作原理是因爲它的目標是登錄和工作,但它會拋出上面顯示的錯誤。 – AlvaroCasvi

回答

3

你得到的錯誤是因爲你在說你期望一個jsonp並提供了一個xml。

$.ajax({ 
    type : "GET", 
    url : URL, 
    dataType : "xml", 
    success : function(service_data) { 
     console.log("OK"); 
     console.log(service_data); 
    }, 
    error : function(msg) { 
     console.log("ERROR"); 
     console.log(JSON.stringify(msg)); 
    } 
}); 

我會改變具體的數據類型

+2

謝謝LT但你的答案不起作用。 其實XML錯誤已經解決,但AJAX調用不起作用,情況變得更糟。 – AlvaroCasvi

+0

據推測,在這種情況下,Adobe Connect不會告知用戶的瀏覽器您的網站有權從Adobe Connect中以其用戶憑據獲取數據。 – Quentin

1

您指定的數據類型爲「JSONP」,但你得到的XML作爲結果。嘗試將數據類型更改爲「xml」。更多信息可在http://api.jquery.com/jquery.ajax/中查到,但是相關的位是:

"xml": Returns a XML document that can be processed via jQuery.

"jsonp": Loads in a JSON block using JSONP. Adds an extra "?callback=?" to the end of your URL to specify the callback. Disables caching by appending a query string parameter, "_=[TIMESTAMP]", to the URL unless the cache option is set to true.

3

一個運動課告訴我大約兩個候選條件的解決方案:

1 - CORS

2 - 代理腳本。

我會告訴你它是否有效,我會嘗試一下。