简体   繁体   English

使用jquery ajax调用aspx文件时,无法传递和检索参数值;

[英]can not pass and retrive parameter value when calling an aspx file using jquery ajax;

Jquery code: jQuery代码:

$('#sendmessage').click(function () {
  var data1 = $('#message').val();
  $.ajax({
    type: "POST",
    url: "NotificationTest.aspx/OnSubmit",
    data:'{name:'+data1+'}',
    contentType: 'application/json; charset=utf-8',
    dataType: 'json',
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + 
        textStatus + "\n\nError: " + errorThrown);
    },
    success: function (result) {
      // alert("We returned: " + result);
      $("#noti_Button").val(result); *** here can not catch value***
    }
  });
});

C# code: here is my c# code to getting value from jquery and return again. C#代码:这是我的c#代码,用于从jquery中获取价值并再次返回。 string is not returned or other thing i ca not underatand. 字符串不返回或其他我不明白的事情。

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

ERRor:Internal server error. ERRor:内部服务器错误。

Make your method static: 使您的方法静态:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM