jQuery ajax POST json

Nul*_*ion 1 ajax jquery post json

所以,这是我的问题(我做过研究并尝试通过查看此处发布的其他类似问题来解决我的问题,但没有奏效)

代码片段(忽略大括号和东西):

json_string = JSON.stringify(json_links); 
var data_obj = { id:n_id, links_json: json_string }; 

$.ajax({ 
url: 'server_api', 
type: 'GET', 
data: data_obj, 
dataType: 'json',
Run Code Online (Sandbox Code Playgroud)

在服务器端,我尝试使用perl模块,JSON和函数,decode_json进行解码,但它会抛出异常,'JSON字符串中的格式错误的UTF-8字符,字符偏移48(在"\ x {92f}之前 - 它 - . ..")'

我尝试使用POST方法和内容类型组合,但它不起作用.jQuery文档指定它默认编码为UTF-8?请帮忙?

Jas*_*ted 6

尝试将数据作为字符串化JSON传递.

$.ajax({
    url: 'server_api',
    type: 'GET',
    data: JSON.stringify(data_obj),
    contentType: 'application/json; charset=utf-8',
    dataType: 'json'
});
Run Code Online (Sandbox Code Playgroud)

  • 您的示例显示data_obj是对象哈希,而不是字符串. (2认同)