2014-05-22 50 views
0

我正在嘗試使用Ajax獲取數據。我的後端框架是CodeIgniter,並出現get_data函數調用錯誤:由於意外的URL,我收到400錯誤

http://localhost/qasim/outlets/[object%20Object] 400 (Bad Request) 

主要的問題是這樣的:在網點,還有一些垃圾是不存在實際的URL。

我該如何解決這個問題?

function get_data(l) 
{ 
    myurl="http://localhost/qasim/outlets/home_controller/get_pros"; 

    $.post({ 
     url:myurl, 
     data:{last:l}, 
     dataType:'json', 

    } 
    ,function (data){alert("success");}); 
} 


$(function(){ 
    $(window).scroll(function (e){ 
     get_data(4); 
     console.log(window.pageYOffset); 
    }); 
}); 

回答

4

您沒有正確使用$.post。它不會將對象作爲第一個參數。

正確用法是:

$.post(myurl, {last:l}, function (data){ 
    alert("success"); 
}, 'json'); 

$.post方法簽名是:

jQuery.post(URL [,數據] [,成功(數據,textStatus,jqXHR)] [ ,dataType])

0

由於「data:{last:1}」,第一個答案有點不正確,因爲第二個參數是對象或String。

正確的是:

$.post(
    myurl, 
    {last:l}, 
    function (data){alert("success");}, 
    'json' 
); 

PS:我看到第一個答案進行修正。一切正常)

+0

不工作相同的問題 –

相關問題