读书人

webservice小疑点

发布时间: 2013-11-21 23:38:25 作者: rapoo

webservice小问题
TestForm.aspx代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestForm.aspx.cs" Inherits="wt.TestForm" %>

<!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 runat="server">
<title></title>
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script src="Scripts/jss/jquery.json-2.3.min.js" type="text/javascript"></script>
<script type="text/javascript">
function clickone() {
var par = { str: "大家好!!!"};
var json_str = $.toJSON(par);
$.ajax({
url: "TestData.asmx/HelloWorld",
type:"POST",
contentType:"application/json;charset=utf-8",
dataType: "json",
data:json_str,
success: function (result) {
alret(result.d);
}
});
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" onclick="clickone()" value="one"/>
</div>
</form>
</body>
</html>


TestData.asmx代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace wt
{
/// <summary>
/// TestData 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class TestData : System.Web.Services.WebService
{

[WebMethod]
public string HelloWorld(string str)
{
return "Hello World" + str;
}
}
}


为何点击“one”按钮没有反应??? webservice ajax
[解决办法]
http://www.cnblogs.com/puresoul/archive/2010/08/19/1803567.html
[解决办法]




function clickone() {
alert('检查是否执行了这里?');
var par = { str: "大家好!!!"};
var json_str = $.toJSON(par);
$.ajax({
url: "TestData.asmx/HelloWorld",
type:"POST",
contentType:"application/json;charset=utf-8",


dataType: "json",
data:json_str,
success: function (result) {
alret(result.d);
}
});
}


[解决办法]
仔细比对,少了什么
[解决办法]
方法里多加几个alert;看走到哪一步..

读书人网 >Web Service

热点推荐