2014-09-11 106 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文件

与一个得到请求它工作正常,但有一个职位...

对不起,您的时间和感谢!每个答案都是有用的!