简体   繁体   English

WebMethod调用问题的Asp.Net(C#)Jquery Ajax

[英]Asp.Net(C#) Jquery Ajax with WebMethod Call Problem

Code Behind: 背后的代码:

 [WebMethod]
        public static string emp()
        {
            return "BlaBla";
        }

Aspx Page: Aspx页面:

$(document).ready(function() {

          $.get("TestPage.aspx/emp", null, function(data) {

                alert(data);

      })
     })

Message Box Output: TestPage.aspx on the page codes 消息框输出:页面代码上的TestPage.aspx

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">    
<head><title>
</title>    
    <style>    
        tr    
        {
                background-color: red;
                color: White;    
        }
        </style>

How to make return string ? 如何使返回字符串?

Thank You. 谢谢。

use 采用

$(document).ready(function() {
  // Add the page method call as an onclick handler for the div.
  $("#Result").click(function() {
    $.ajax({
      type: "POST",
      url: ""TestPage.aspx/emp",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
        // Replace the div's content with the page method's return.
        $("#Result").text(msg.d);
      }
    });
  });
});

In your page use 在您的页面中使用

<div id="Result">Click here to return the string</div>

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

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