jQuery的阿贾克斯 - 设置过程数据为假突破我的AJAX请求 [英] jQuery Ajax - Setting processData to false breaks my AJAX request

查看:151
本文介绍了jQuery的阿贾克斯 - 设置过程数据为假突破我的AJAX请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在用Google搜索了一会儿,就只能找什么过程数据:假的一样。我找不到谁经历了同样的问题任何人。

I've googled for a while now and can only find what processData: false does. I can't find anyone who has experienced this same issue.

我通过JSON回服务器,不希望jQuery来自动将数据转换为查询字符串,所以我设置过程数据为false。我可以看到请求射击,如果我拿出过程数据,但是当我把它在我没有看到正在作出任何请求(使用萤火虫和放大器; Chrome浏览器开发工具)。

I'm passing JSON back to the server and do not want jquery to automatically convert the data to a query string so I'm setting processData to false. I can see the request firing if I take out processData, but as soon as I put it in I do not see any requests being made (using Firebug & Chrome dev tools).

$.ajax({
            url: myUrl,
            type: "POST",
            data: {foo: "bar"},
            processData: false,
            contentType: 'application/json'
        });

我最初提出要求有点比这更复杂,但我已经简化到尽量缩小这个问题,但这个简单的一块code也不管用(再次,它的工作,如果我注释掉过程数据)。另外,我没有看到在控制台的任何JavaScript错误。

The request I was initially making was a bit more complex than this but I've simplified it to try to narrow down the problem but this simple piece of code does not work either (again, it does work if I comment out processData). Also, I am not seeing any Javascript errors in the console.

任何帮助将是很大的AP preciated!

Any help would be greatly appreciated!

修改对于未来的谷歌:由于lonesomeday指出,如果提供任何一个JS对象或格式不正确的JSON字符串,jQuery将不会引发任何错误。它只是不火的请求。

EDIT For future Googlers: As lonesomeday pointed out, jQuery will not throw any errors if you supply either a JS object or an incorrectly formatted JSON string. It will simply not fire the request.

推荐答案

您想通过数据作为JSON。你传递了一个JavaScript对象。 JSON是序列化的Javascript对象字符串,以便它们可以绕过去了,没有兼容性问题的一种方式。

You want to pass the data as JSON. You are passing a Javascript object. JSON is a way of serializing Javascript objects to strings so that they can be passed around without compatibility issues.

您确实想通过JSON字符串中的:

You actually want to pass the JSON in a string:

$.ajax({
    url: myUrl,
    type: "POST",
    data: '{"foo": "bar"}',
    processData: false,
    contentType: 'application/json'
});

这篇关于jQuery的阿贾克斯 - 设置过程数据为假突破我的AJAX请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆