tôi làmAjax Gọi WebPage Phương pháp không hoạt động
<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>
Và Script quản lý của tôi là
<asp:ScriptManager ID="ScriptManager1"
EnableScriptGlobalization="true"
EnableScriptLocalization="true"
EnablePageMethods="true"
EnablePartialRendering="true" runat="server" />
Nhưng khi tôi thực hiện chọn chức năng tôi có gì ... không có tin nhắn nào cả.
Lỗi đăng nhập:
[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)
Và phương pháp web của tôi:
<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
Nếu tôi chỉ làm alert (CallPageMethod ("SelectBook", thành công, thất bại, ........ ...)) Tôi có thể thấy "không xác định", nhưng những gì không xác định ??? Tôi đã cố gắng để gỡ lỗi javascript này nhưng không thể sửa chữa nó. Nó đã được làm việc và tôi hiểu nó phải hoạt động như thế nào, nhưng tôi không biết tại sao nó lại bị hỏng và cách khắc phục nó. Giúp tôi với nó.
Một số biết thêm thông tin
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
tại sao gần?
Cùng với $ .get() hoặc $ .getJSON() :( – Cynede
sử dụng firebug và kiểm tra xem có bất kỳ JSON nào giống như đầu ra không ... – Axxxon
bài đăng được cập nhật với nhật ký lỗi – Cynede