以下爲我工作:
function GetShoppingCartData() {
jQuery.ajax({
type: "POST",
url: "DesktopModules/EcomDnnProducts/AjaxProductDisplay.aspx/GetShoppingCartData",
data: "{'CartId': '" + jQuery(".shoppingcartid").attr("value") + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
//jQuery('#productattributesdata').text(msg.d);
buildShoppingCart(msg.d);
},
fail: function (msg) {
jQuery('#productattributesdata').text(msg.d);
}
});
}
你並不需要的「數據顯示:......」有點
我不得不更改我的ASP頁面,得到它的工作。 我的函數如下:
<System.Web.Services.WebMethod()> _
Public Shared Function GetShoppingCartData(ByVal CartId As String) As String
Dim ReturnString As String = ""
Try
ReturnString = "test1;test2;test3"
Catch ex As Exception
'ProcessModuleLoadException(Me, exc)
Dim DataLogger As New DataLogger
DataLogger.WriteToEventLog("Error", ex.Message & " - " & ex.StackTrace)
End Try
Return ReturnString
End Function
會看看是否有任何其他設置...
添加以下到Web.config授予權限的事情被稱爲:
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
不知道這是否是缺失的位。
一些更多的資源: http://msdn.microsoft.com/en-us/library/byxd99hx(v=vs.80).aspx
http://www.dotnetcurry.com/ShowArticle.aspx?ID=109
http://forums.asp.net/t/1298480.aspx/1
HTH 肖恩
刪除的contentType。 – insomiac
產生相同的結果。 – notnot
所以當你把「application/json」作爲內容類型的時候,你在後端接收數據爲「JSON」? – insomiac