代码背后:
[WebMethod]
public static string emp()
{
return "BlaBla";
}
Aspx Page:
$(document).ready(function() {
$.get("TestPage.aspx/emp", null, function(data) {
alert(data);
})
})
消息框输出:页面代码上的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>
如何制作返回字符串?
谢谢。
答案 0 :(得分:3)
使用
$(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);
}
});
});
});
在您的页面中使用
<div id="Result">Click here to return the string</div>