jQuery的将数据传递到AJAX功能 [英] Jquery passing data to ajax function
本文介绍了jQuery的将数据传递到AJAX功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在传递数据值对jQuery的Ajax功能的问题。
I'm having problems passing data values to the Jquery Ajax function.
我一直在使用的getJSON函数和工作正常,但现在我想使用AJAX功能,我无法工作,如何传递价值。
I have been using the getJSON function and that was working fine but now I want to use the ajax function and I can't work out how to pass in values.
$.ajax({
type: "POST",
url: '../../../WebServices/ImageLibrary.svc/getimagesinfolder',
dataType: 'json',
data: "{ 'id', '2' }",
contentType: "application/json; charset=utf-8",
success: function (data)
{
alert('hello');
}
});
这是正确的?谁能告诉我,我要去哪里错了?
Is this right? Can anyone tell me where i'm going wrong?
感谢
推荐答案
您已经无效的JSON:
You have invalid JSON:
"{ 'id', '2' }"
我会建议你调用它像这样,因为它会采取正确的编码参数的护理:
I would recommend you calling it like this as it will take care of properly encoding your parameters:
$.ajax({
type: "POST",
url: '../../../WebServices/ImageLibrary.svc/getimagesinfolder',
dataType: 'json',
data: JSON.stringify({ id: '2' }),
contentType: "application/json; charset=utf-8",
success: function (data) {
alert('hello');
}
});
这篇关于jQuery的将数据传递到AJAX功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文