jquery $ .post没有发送帖子数据

时间:2014-09-11 09:30:09

标签: javascript jquery ajax post

我试图向服务器发出帖子请求,但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" );

2 个答案:

答案 0 :(得分:0)

解决方案:

改变这个: INC / API / do.login.ajax

INC / API / do.login.ajax / index.php的

有一个get请求它工作正常,但有一个帖子......

抱歉花时间谢谢!每个答案都很有用!

答案 1 :(得分:-1)

根据jquery API doc。

    $.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,以检查至少是否正常通话以及error_reporting(E_ALL); 如果出现问题。