2011-12-17 122 views
3

我得到了错误:jQuery的AJAX POST ...请求失败:URI太长(比8190更长)

request failed: URI too long (longer than 8190)

我见过的StackOverflow上其他职位为这一个。这些职位的建议:

  • 在不改变Apache的设置(同意)
  • 使用后,没有得到
  • 不使用jsonp与后

我使用jQuery的AJAX以POST:

$.ajax({ 
     url: "test.php", 
     dataType: "json", 
     data: paras, 
     type: "POST", 
     success: function(ret){callback(ret);} 
    }); 

这是我的印象,你可以使用json而不是jsonp。正确?如果是这样,为什么我仍然可能得到错误?

回答

6

您应该尝试将proccessData设置为false。

从文档:

By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded". If you want to send a DOMDocument, or other non-processed data, set this option to false.

这样可以防止数据被添加到URL:

$.ajax({ 
    url: "test.php", 
    dataType: "application/json", 
    data: paras, 
    type: "POST", 
    proccessData: false, // this is true by default 
    success: function(ret){callback(ret);} 
}); 

老实说,我认为这是自动的,但由于您的网址太长,它的价值一枪。

0

我在使用jQuery提交大型表单时遇到了这个问题,并且能够通过添加this plugin来解决此问题。

例如,使用下面的代码添加插件后提交表单解决我这个问题:

$(formSelectorHere).ajaxSubmit({ 
     url: myURL, 
     type: 'post', 
     contentType: "multipart/form-data", 
     data: $(this).serialize(), 
     success: function(data) { 
     function(data) { 
      //success code here// 
     } 
    }); 

如果你不使用此提交表单,这可能不是有关你并不会解决你的问题,但这是出现这个问题的最常见情况,所以我觉得值得一提。 (该插件也应该能够使用JSON提交表单,但没有亲自测试过)。