2011-12-17 121 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提交表單,但沒有親自測試過)。