2016-12-30 4 views
0

aspxページでjquery関数を呼び出そうとしていますが、エラーメッセージが表示され続けます。私は段階的にデバッグを試みましたが、それでも何かを把握できませんでした。親切にも誰でも問題の可能性があることを私に助言することができます。ありがとう。 私はasp.netでのJQueryの問題?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dtata.aspx.cs" Inherits="Dtata" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 
<script src="/scripts/jquery-3.1.1.min.js"></script> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <div> 
    </div> 
     <script type="text/javascript"> 
      klm(); 
      function klm() { 
       $.ajax({ 
        type: "POST", 
        url: "Dtata.aspx/Hello", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 
        data: { name: 'hello' }, 
        success: function (result) { 
         response(result.d); 
         Counter() //<-- CALL OTHER AJAX METHOD TO INCREASE COUNTER ON BACK END 
        }, 
        error: function (result) { 
         alert('There is a problem processing your request'); 
        } 
       }); 
      } 


      function Counter() { 
       $.ajax({ 
        type: "POST", 
        url: "Dtata.aspx/Counter", 
        contentType: "application/json; charset=utf-8", 
        dataType: "json", 

        success: function (result) { 
         console.log(result.d); 
        }, 
        error: function (result) { 
         alert('There is a problem processing your request'); 
        } 
       }); 

      } 

     </script> 



    </form> 


</body> 
</html> 

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class Dtata : System.Web.UI.Page 
{ 
    private int _counter = 0; 

    protected void Page_Load(object sender, EventArgs e) 
    { 


    } 

    [WebMethod] 
    public static string Hello(string name) 
    { 
     return name; 
    } 

    [WebMethod] 
    public int Counter(int _counter) 
    { 
     Console.WriteLine("I have been called"); 

     this._counter = this._counter +1; 
    return this._counter; 
    } 
} 
+0

URLが間違っていると、エラーコールが最も頻繁に呼び出されます。ブラウザにURLを貼り付けると、Dtata.aspx/Counterにアクセスできますか? – DiegoS

+0

@DiegoS: - そうです。それはURLにアクセスできません。私はC#クラスの中のメソッドにアクセスできるように、私はURLとして何を置くべきですか? –

+0

パラメータとして文字列名をとるHelloメソッドをC#クラスに追加する必要があります:) – DiegoS

答えて

0

uは、この行を変更してください可能性が 'リクエストの処理に問題があります' 失敗応答」を得続ける:これまで

data: { name: 'hello' }, 

data: "{ 'name' : 'hello' }", 

まだ場合をエラーが発生しましたか? 正確に何が起こったか知りたい場合は、この行を変更してください:

その後、

error: function (result) { 
        alert(result.responseText); 
       } 

から

error: function (result) { 
        alert('There is a problem processing your request'); 
       } 

と、それは誤りだお送りいたします。