2011-05-22 130 views
1

我測試了一個從web服務請求數據的vanilla html網站。我的網站在本地端口81上運行,網絡服務在端口61616上運行。jQuery 1.6跨域請求不起作用

這個工作在jQuery 1.4中。

我已經升級到1.6,並認真考慮回去,因爲跨域的實現被打破。

在IE中,我找不到資源,顯示的URL是除hostname:port之外的所有內容,沒有它,資源(當然)將不會被找到。

在Chrome中出現以下錯誤:XMLHttpRequest無法加載http://localhost:61616/ZifmiaService/Register/foo/bar/foo bar/[email protected]。 Access-Control-Allow-Origin不允許原產地http://localhost:81

Web服務具有Access-Control-Allow-Origin:* set,因此服務器端允許跨域請求。

我也有:

$ .support.cors = true;

在我的客戶端JavaScript代碼。

我沒有使用jsonp,也不認爲我需要使用正確的設置。

我還能做什麼錯,或者我應該向jQuery報告錯誤?

    • 添加的代碼* *

如上描述的URL成爲61616網址。

this.register = function (username, password, nickName, emailAddress, callback, errorCallback) { 
    $.ajax({ 
     type: "GET", 
     url: ZifmiaRegister.format(username, password, nickName, emailAddress), 
     crossDomain: true, 
     dataType: "json", 
     success: function (zifmiaRegistrationViewModel) { 
      callback(zifmiaRegistrationViewModel); 
     }, 
     error: function (xhr, textStatus, errorThrown) { 
      errorCallback(xhr, textStatus, errorThrown); 
     }, 
     beforeSend: function() { $(ajaxLoading).show(); }, 
     complete: function() { $(ajaxLoading).hide(); } 
    }); 
} 
+0

您的項目中需要升級到1.6的需求有哪些變化? – 2011-05-22 05:36:00

+0

@david,發佈你的ajax代碼,我不認爲1.6有什麼問題,有些設置可能已經改變..發佈你的ajax代碼,我們可以看到有什麼錯誤。 – kobe 2011-05-22 05:48:07

+0

在主要問題中添加了代碼。我使用字符串格式將服務URL(該服務構建在WCF 4.0 Rest中)組合在一起。您可以在http://zifmia.textfyre.com/ZifmiaService/help – 2011-05-22 14:35:02

回答

1

試着追加「?callback =?」到發出ajax請求的URL。例如,「http:// localhost:61616/ZifmiaService/Register/foo/bar/foo bar/[email protected]?callback=?」 。

如果您的URL包含查詢字符串,則應添加「& callback =?」。

+0

這有助於我的問題。 – 2011-06-07 22:07:05