2012-09-06 14 views
0

我追平了本教程中,http://www.ezzylearning.com/tutorial.aspx?tid=5869127ASP.NET web服務的願望AJAX,JSON,jQuery和vb.net

它完美的作品。我現在試圖做的是將aspx內容作爲html文件進行託管。這個html文件託管在我的筆記本電腦上的wampserver上。我的測試服務器上託管的asp.net代碼。當我嘗試訪問時,出現以下錯誤:

Resource interpreted as Script but transferred with MIME type text/html:  "http://201.x.x.x/testAjax/Default.aspx/AddProductToCart?callback=jQuery17103264484549872577_1346923699990&{%20pID:%20%226765%22,%20qty:%20%22100%22,%20lblType:%20%2220%22%20}&_=1346923704482". jquery.min.js:4 

Uncaught SyntaxError: Unexpected token < 

我不確定如何解決此問題。

index.html的代碼

$(function() { 
     $('#btnAddToCart').click(function() { 
      var result = $.ajax({ 
       type: "POST", 
       url: "http://202.161.45.124/testAjax/Default.aspx/AddProductToCart", 
       crossDomain: true, 
       data: '{ pID: "6765", qty: "100", lblType: "20" }', 
       contentType: "application/json; charset=utf-8", 
       dataType: "jsonp", 
       success: succeeded, 
       failure: function (msg) { 
        alert(msg); 
       }, 
       error: function (xhr, err) { 
        alert(err); 
       } 
      }); 
     }); 
    }); 

    function succeeded(msg) { 
     alert(msg.d); 
    } 

    function btnAddToCart_onclick() { 

    } 

</script> 
</head> 
<body> 
     <form name="form1" method="post"> 
    <div> 
    <input type="button" id="btnAddToCart" onclick="return btnAddToCart_onclick()" 
     value="Button" /> 
</div> 
</form> 

aspx.vb

Imports System.Web.Services 
Imports System.Web.Script.Services 

<ScriptService()> 
Public Class WebForm1 
Inherits Page 

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    Session("test") = "" 
End Sub 

<WebMethod()> 
<ScriptMethod(UseHttpGet:=False, ResponseFormat:=ResponseFormat.Json)> 
Public Shared Function AddProductToCart(pID As String, qty As String, lblType As String) As String 

    Dim selectedProduct As String = String.Format("+ {0} - {1} - {2}", pID, qty, lblType) 

    HttpContext.Current.Session("test") += selectedProduct 

    Return HttpContext.Current.Session("test").ToString() 

End Function 

End Class 

回答