使用jQuery Ajax获取字符串数据

时间:2016-09-09 07:09:23

标签: jquery ajax asp.net-ajax

$.ajax({

        type: "GET",
        url: "Default.aspx/getData",
        contentType: "text/plain",
        dataType: "text",
        success: function (data) {
            debugger;
            $("#Content").text(data);
        },
        failure: function (response) {
             debugger;
            alert(response.d);
        }
    });


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

输出

<!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> <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.js" integrity="sha256-slogkvB1K3VOkzAI8QITxV3VzpOnkeNVsKvtkYLMjfk=" crossorigin="anonymous"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function () { alert('hello') $.ajax({ type: "GET", url: "Default.aspx/getData", contentType: "text/plain", dataType: "text", success: function (data) { debugger; $("#Content").text(data); }, failure: function (response) { debugger; alert(response.d); } }); }); </script> <title> </title></head> <body> <form name="form1" method="post" action="Default.aspx" id="form1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJOTczNTMyNjI5ZGTgWl4jdLCmZhtDDe7OMipxIC2Qxg==" /> </div> <div> <input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="DA4CC853" /> </div> <span id="Label1">Label</span> </form> <div id="Content"> </div> </body> </html> 

而不是“你好”

0 个答案:

没有答案