12,162
社区成员
发帖
与我相关
我的任务
分享
$.ajax({
type: 'POST',
url: "WebService2.asmx/HelloWorld",
contentType: "application/json:charset=utf-8",
datatype: 'json',
daa:{str:'sadsad'},
beforeSend: function (XMLhttpRequest) {
alert('loading');
},
success: function (data) {
alert($(data).find('string').text());
},
error: function (error) {
alert(error.responseText);
}
});
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
[System.Web.Script.Services.ScriptService]
public class WebService2 : System.Web.Services.WebService {
public WebService2 () {
//如果使用设计的组件,请取消注释以下行
//InitializeComponent();
}
//[WebMethod]
//public string HelloWorld() {
// return "Hellow World";
//就是默认的WebService的代码,然后加了个参数
[WebMethod]
public string HelloWorld(string str)
{
return "Hellow World and"+str;
}