2017-08-28 6 views
1

私はその時にクリックしているasp.netボタンのIDを渡そうとしていますが、次のことを試していますが、コンパイラが好きではないようです。私のjqueryは少し錆びますjqueryメソッドにボタンのidを渡す

データ:

<script type = "text/javascript"> 
    function AddToFavourites() { 
     var element = $(this); 

     $.ajax({ 
      type: "POST", 
      url: "/dynamic/Favourite.aspx/AddToFavourites", 
      data: '{productId:'+ element.attr('id') + "}", 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: OnSuccess, 
      failure: function(response) { 
       alert(response.d); 
      } 
     }); 
    } 
    function OnSuccess(response) { 
     alert(response.d); 
    } 
</script> 

それがオン故障していることをここでこの行がある:これは私のコードである '{商品コード:' + element.attr( 'ID')+ "}" 、

また、この呼び出しの直後に、人が製品を好んだことを確認したら、fa-heartアイコンを赤に変更する結果を返します。

編集3

は、コンソールの出力を表示するには.logに

VM41:1 POST http://localhost:52448/dynamic/Favourite.aspx/AddToFavourites 500 (Internal Server Error) 
(anonymous) @ VM41:1 
send @ jquery.js:9664 
ajax @ jquery.js:9215 
AddToFavourites @ Aspen:24 
onclick @ Aspen:919 

かなり奇妙な私は、そのファイル

<WebMethod()> _ 
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ 
Public Shared Function AddToFavourites(productId As String) As String 
Dim constr As String = ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString 
    Using con As New SqlConnection(constr) 
     Dim strQuery As String 
     'set up the sql command 
     Dim oSqlCommand As New SqlClient.SqlCommand 
     ' oSqlCommand.Connection = oSqlConn 

     Dim oDataAdapter As New SqlClient.SqlDataAdapter 
     Dim oLinesTable As New DataTable 

     Dim strProductID As String 
     strProductID = productId.Replace("product_", "") 

    End Using 

    Return "" 

End Function 

答えて

0

変更に後ろの私のコード内の関数を持っているとして、あなたのラインdata: '{productId:'+ element.attr('id') + "}",

と:

data: {'productId': element.attr('id') }, 
関連する問題