webservice
[WebMethod]
public int checkIshege(int fid)
{
int n = 0;
StringBuilder Str = new StringBuilder();
Str.Append("Update RM_Admin_Work");
Str.Append(" set [Ishege]=@Ishege"); SqlParameter[] parameters ={
new SqlParameter("@Ishege",SqlDbType.Int,4)
}; parameters[0].Value = fid;
RM.DataProvider.SqlDBO db = new SqlDBO();
n = db.execnonsql_ExecuteNonQuery(Str.ToString(), parameters);
return n;
}
js function NotAwards(id) {
alert(id);
$.ajax({
type:"post",
contentType:"text",
url:"/WebService/check.asmx/checkIshege",
data:"{'fid':'" + id + "'}",
success:function() { }
});
}
这个id可以alert的出来,我上面的checkIshege这个方法加了断电,但是 调试的就是跳不同过来怎么回事大侠
将你的 [WebMethod] 方法移到ajax的这个页面,并用state修饰,看下能否调用
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="Magic.PartySystem.UI.Pages.WebForm3" %><!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="../Script/jquery-1.6.2.min.js" type="text/javascript"></script>
</head>
<body>
<script>
function callweb()
{alert(2);
$.ajax({
type: "post",
contentType: "application/json",
url: "WebForm3.aspx/checkIshege",
data: "{'fid': 12}",
success: function ()
{
alert(1);
}
});
}
</script>
<form id="form1" runat="server">
<div>
<input type="button" onclick="callweb()" value="call" />
</div>
</form>
</body>
</html>cs文件
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;namespace Magic.PartySystem.UI.Pages
{
public partial class WebForm3: Page
{
protected void Page_Load( object sender, EventArgs e )
{ } [WebMethod]
public static void checkIshege( int fid )
{
string a = "asdfa";
}
}
}
然后,JQ调用WebService最后加上Content-Type:application/json;utf-8属性,因为默认的JQ不知道是什么处理方式。然后记得在输出的Success函数里进行数据转换,例如var json = eval('(' + msg + ')');
改成
$.ajax({
type:"post",
contentType:"json",
dataType:"application/json;charset=uft-8"
url:"/WebService/check.asmx/checkIshege",
data:"{'fid':'" + id + "'}",
success:function(reuslit) {
alert(result.d) }
});
一定要加个d。放回值
你这样写 }
改成
$.ajax({
type:"post",
contentType:"json",
dataType:"application/json;charset=uft-8"
url:"/WebService/check.asmx/checkIshege",
data:"{fid:" + id + "}",
success:function(reuslt) {
alert(result.d) }
});
一定要加个d。放回值