javascript jquery ajax请求与json抛出解析器错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25201728/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jquery ajax request with json throwing parsererror
提问by Shaggy
I have searched lot of on this issue and tried almost everything but it doesn't seem to be work so posting it here.
我在这个问题上搜索了很多,几乎所有的东西都试过了,但似乎没有用,所以把它贴在这里。
I am trying to make jquery ajax call to ashx
handler by passing json data. But my request doesnt reach till handler GetBalance.ashx
我正在尝试ashx
通过传递 json 数据使 jquery ajax 调用处理程序。但我的请求直到处理程序才到达GetBalance.ashx
code :
代码 :
var mydata = {};
$.ajax({
url: 'Handlers/GetBalance.ashx?type=authenticateRequest',
type: 'post',
dataType: 'json',
cache: false,
data: mydata,
success: function (data) {
},
error: function (xhr, status) {
console.log(status);
console.log(xhr.responseText);
}
});
in console it prints
在控制台中打印
parsererror
(empty string)
What i am doing wrong ? It should reach till .ashx
before it gives any response parse error
我做错了什么?它应该.ashx
在它给出任何响应解析错误之前到达
Edit:
编辑:
Changed as suggested by answer
按照答案的建议进行更改
采纳答案by Ronak Patel
Replace your line
更换您的线路
data: mydata,
with
和
data: JSON.stringify(mydata),
contentType: "application/json",