2014-09-11 111 views
0

即時嘗試向服務器發出發佈請求,但jquery不發送任何發佈日期。

我已經嘗試過使用方法:(建議我在網上找到了)

var postdata = {'username':username,'password':password,'src':'web'}; 

,而不是

var postdata = 'username=' + username + '&pass=' + password + '&src=web'; 

這是我的jQuery代碼:

var username = $('#uForm_un').val(); 
var password = $('#uForm_pw').val(); 
var postdata = 'username=' + username + '&pass=' + password + '&src=web'; 
console.log(postdata);//output: username=administrator&pass=password&src=web 
$.post(
    "inc/api/do.login.ajax", 
    postdata, 
    function (data) { 
     console.log(data);//output: a vardump($_POST) wich is empty. 
    } 
); 

瀏覽器數據:

Remote Address:62.***.**.**:80 
Request URL:***********/inc/api/do.login.ajax/ 
Request Method:GET 
Status Code:200 OK 
Request Headersview source 
Accept:*/* 
Accept-Encoding:gzip,deflate,sdch 
Accept-Language:nl-NL,nl;q=0.8,en-US;q=0.6,en;q=0.4 
Cache-Control:no-cache 
Connection:keep-alive 
Cookie:anonymous=-81523622186; windowtop=100; LanguageId=1; CurrencyId=1; space_history=%7B%221%22%3A%2220%22%7D; eventId=1; OrderId=201424754035; filter_starttime=6%3A00; filter_endtime=12%3A00; _ga=GA1.2.2031844175.1410181977; __atuvc=13%7C37; PHPSESSID=4x1xc4ca4238a0b923820dcc509a6f75849b; filter_display_mode=grid; filter_search=; filter_where=eindhoven; filter_startdate=01/09/2014; filter_enddate=05/09/2014; filter_order=itemdate; filter_dayparts=; filter_distance=100000; filter_categories=; list=%2C2797 
Host:********.nl 
Pragma:no-cache 
Referer:***************/index.php?action=editvisit 
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.103 Safari/537.36 
X-Requested-With:XMLHttpRequest 
Response Headersview source 
Connection:Keep-Alive 
Content-Encoding:gzip 
Content-Length:156 
Content-Type:text/html; charset=utf-8 
Date:Thu, 11 Sep 2014 09:15:03 GMT 
Keep-Alive:timeout=5, max=88 
Server:Apache/2.2.22 (Debian) 
Vary:Accept-Encoding 
X-Powered-By:PHP/5.4.4-14+deb7u14 

編輯:

現在我用這個代碼,但具有相同的結果...

$.post("inc/api/do.login.ajax",{ 
       username : ""+$('#uForm_un').val()+"", 
       pass  : ""+$('#uForm_pw').val()+"", 
       src  : "web" 
      }).done(function(data) { 
       console.log(data); 
      }, "json"); 
+0

我diddnt downvote你的答案!我不能downvote他們沒有得到150代表... – 2014-09-11 09:46:13

+0

如何使用網絡調試器如Fiddler或Wireshark來調查是怎麼回事? http://www.telerik.com/download/fiddler,https://www.wireshark.org/ – theMarceloR 2014-09-11 10:52:35

回答

-1

據jQuery的API文檔。

$.post("inc/api/do.login.ajax", 
      { username : $('#uForm_un').val(), password : $('#uForm_pw').val() }, 
      function (data){ 
       /*...callback...*/ 
      }, "json"); 

http://api.jquery.com/jquery.post/

另外,我想嘗試$_REQUEST代替$ _ POST在後端,以檢查是否至少調用是OK,萬一error_reporting(E_ALL); 什麼是錯的。

+0

Reqeust是空的,並且使用你的代碼diddnt做任何diffrence .. – 2014-09-11 09:51:19

0

解決方案:

改變這一點: INC/API/do.login.ajax

INC/API/do.login.ajax/index.php文件

與一個得到請求它工作正常,但有一個職位...

對不起,您的時間和感謝!每個答案都是有用的!