我
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript">
function CallPageMethod(methodName, onSuccess, onFail) {
var args = '';
var l = arguments.length;
if (l > 3) {
for (var i = 3; i < l - 1; i += 2) {
if (args.length != 0) args += ',';
args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
}
}
var loc = window.location.href;
loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "Report.aspx" : loc;
$.ajax({
type: "POST",
url: loc + "/" + methodName,
data: "{" + args + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: onSuccess,
fail: onFail
});
}
function success(response) {
alert(response.d);
}
function fail(response) {
alert("Ошибка.");
}
function select() {
...........
CallPageMethod("SelectBook", success, fail, ...........);
}
</script>
和我的脚本管理器
<asp:ScriptManager ID="ScriptManager1"
EnableScriptGlobalization="true"
EnableScriptLocalization="true"
EnablePageMethods="true"
EnablePartialRendering="true" runat="server" />
但是,当我执行select函数我什么都没有......没有任何消息都没有。
But when I execute select function I got nothing ... no messages at all.
错误日志:
[ArgumentException]: Unknown web method SelectBook.
Parameter name: methodName
at System.Web.Script.Services.WebServiceData.GetMethodData(String methodName)
at System.Web.Handlers.ScriptModule.OnPostAcquireRequestState(Object sender, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
和我的Web方法:
<WebMethod()> Public Function SelectBook(ByVal values As String, ByVal valuesG As String, ByVal valuesX As String, ByVal valuesXG As String) As String
'....
Return If(((vals.Length = valsG.Length) And (valsX.Length = valsXG.Length)), SQLModule.UpdateAdvCode(vals, valsG, valsX, valsXG), "Ошибка чтения диспетчерских кодов")
End Function
如果我只做警报(CallPageMethod(SelectBook,成功,失败,...........)),我可以看到不确定,但不确定是什么???我试着调试这个JavaScript,但不能修复它。它是工作,我了解它必须工作,但我只是不知道为什么它打破了现在如何解决它。帮我用它吧。
If I only do alert( CallPageMethod("SelectBook", success, fail, ...........) ) I can see "undefined" , but what undefined ??? I was tried to debug this javascript but can't fix it. It was worked and I understand how it must works, but I just have no idea why it is broken for now and how to fix it. Help me with it please.
一些详细信息
Server ASP.NET Development Server/10.0.0.0
Date Thu, 03 Feb 2011 11:30:51 GMT
X-AspNet-Version 4.0.30319
Cache-Control private
Content-Type text/html; charset=utf-8
Content-Length 3517
Connection Close
为什么关闭?
why close ?
问题解决了......
Problem solved ....
<WebMethod()> Public SHARED Function SelectBook(ByVal values As String, ByVal valuesG As String, ByVal valuesX As String, ByVal valuesXG As String) As String
'....
Return If(((vals.Length = valsG.Length) And (valsX.Length = valsXG.Length)), SQLModule.UpdateAdvCode(vals, valsG, valsX, valsXG), "Ошибка чтения диспетчерских кодов")
End Function
我花2天,看看它必须是共享的> _&LT;
I spend 2 days to see it must be Shared >_<