asp.net ajax webmethod 返回 [object XMLHttpRequest]
我正在对 Webmethod (Pagemethod) 进行简单调用,但不断收到此错误:
[对象 XMLHttpRequest]
Javascript:
var id = $('#' + this.Div).attr('id');
var test = $('#' + id).parent('.Prod-top-time').prev().attr('id');
test = test.replace('navn_', '');
var parameters = {'auktionid': test};
$.ajax({
type: "POST",
url: "Default.aspx/AuctionEnd",
data: JSON.stringify(parameters),
//data: JSON.stringify({ auktionid: 34}),
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function(ret)
{
if (ret.hasOwnProperty('d'))
stuff(ret.d);
else
stuff(ret);
}
});
function stuff(msg) {
alert(msg);
}
在第一部分中,我从 div id 中提取一个值。这是用作参数的数字。
Webmethod 就这么简单:(目前仅用于测试)
[WebMethod]
public static string AuctionEnd(int auktionid)
{
return auktionid.ToString();
}
无论我向它抛出什么,它都会返回该错误。
I'm making a simple call to a Webmethod (Pagemethod), but I keep getting this error:
[object XMLHttpRequest]
Javascript:
var id = $('#' + this.Div).attr('id');
var test = $('#' + id).parent('.Prod-top-time').prev().attr('id');
test = test.replace('navn_', '');
var parameters = {'auktionid': test};
$.ajax({
type: "POST",
url: "Default.aspx/AuctionEnd",
data: JSON.stringify(parameters),
//data: JSON.stringify({ auktionid: 34}),
contentType: "application/json; charset=utf-8",
dataType: "json",
error: function(ret)
{
if (ret.hasOwnProperty('d'))
stuff(ret.d);
else
stuff(ret);
}
});
function stuff(msg) {
alert(msg);
}
In the first part, I extract a value from a div id. This is a number used as parameter.
The Webmethod is as simple as this: (Just for testing so far)
[WebMethod]
public static string AuctionEnd(int auktionid)
{
return auktionid.ToString();
}
No matter what I throw at it, it returnes that error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能在隧道尽头找到一盏灯
当你想在 jquery 中使用 WebMethod 时,你必须将此标签添加到 web.config
祝你好运
i could find a light at the end of the tunnel
when you want use WebMethod in jquery , you must add this tag to web.config
good luck
您正在消息框中显示错误对象。错误函数返回如下:
请求失败时调用的函数。该函数接收三个参数:jqXHR(在 jQuery 1.4.x 中为 XMLHttpRequest)对象、描述发生的错误类型的字符串以及可选的异常对象(如果发生)。第二个参数的可能值(除了 null 之外)有“timeout”、“error”、“abort”和“parsererror”。这是一个 Ajax 事件。从 jQuery 1.5 开始,错误设置可以接受函数数组。每个函数都会被依次调用。注意:跨域脚本和 JSONP 请求不会调用此处理程序。
您需要显示 jqXHR 对象的详细信息。
jqXHR 对象
从 jQuery 1.5 开始,$.ajax() 返回的 jQuery XMLHttpRequest (jqXHR) 对象是浏览器本机 XMLHttpRequest 对象的超集。例如,它包含responseText 和responseXML 属性,以及getResponseHeader() 方法。当传输机制不是 XMLHttpRequest 时(例如,JSONP 请求的脚本标记),jqXHR 对象会尽可能模拟本机 XHR 功能。
所有信息都位于
http://api.jquery.com/jQuery.ajax/
和示例我与错误处理程序一起使用的 ajax 调用是:
注意错误处理程序中的差异
更新的示例:
You are showing the error object in the message box. The error function returns as follows:
A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". This is an Ajax Event. As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests.
you need to show the details of the jqXHR object.
The jqXHR Object
The jQuery XMLHttpRequest (jqXHR) object returned by $.ajax() as of jQuery 1.5 is a superset of the browser's native XMLHttpRequest object. For example, it contains responseText and responseXML properties, as well as a getResponseHeader() method. When the transport mechanism is something other than XMLHttpRequest (for example, a script tag for a JSONP request) the jqXHR object simulates native XHR functionality where possible.
All information is at
http://api.jquery.com/jQuery.ajax/
And example ajax call i use with error handler is:
Note the difference in the error handler
Updated Example: