【发布时间】:2011-08-31 16:40:06
【问题描述】:
所有,
我正在尝试将 html 数据传递给存在于 .NET/c# 中的 Web 服务。我正在使用 JQUERY,但继续收到“发布数据失败”的错误。我的 ajax 脚本或后面的代码中的语法是否错误?感谢您的帮助。
$(function () {
$("[id$=rdbSaveAjax]").click(function () {
var markedUPHTML = $("[id$=wrapper]").html();
var postData = "{'HTMLData' : '" + markedUPHTML + "'}";
$.ajax({
type: "POST",
url: "Role.asmx/test",
data: JSON.stringify({html: postData}),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert("successfully posted data");
},
error: function (data) {
alert("failed posted data");
alert(JSON.stringify(postData));
}
});
});
});
背后的webservice代码:
/// <summary>
/// Summary description for Role
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Role : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string test(string html)
{
string strHTMLData = html;
return html;
}
}
【问题讨论】:
标签: c# .net web-services jquery