AngularJS不发送任何帖子数据

时间:2014-05-27 12:16:55

标签: javascript ajax json angularjs xmlhttprequest

我在angularjs中发送了一个AJAX帖子请求,但它没有发送任何内容,因为我在服务器端检查到达的内容是什么,使用:

print_r($_REQUEST);

但是当我使用时:

print_r(json_decode(file_get_contents("php://input")));

它起作用,因为我知道数据是以JSON块发送的,而不是常规的表单格式。

现在我已经想出了如何使用类似于jQuery的标题发送帖子数据,但我仍然在服务器端使用常规$_REQUEST$_POST得不到任何内容。

这是用Javascript编写的代码块。值得一提的是: 我已经使用console.log()检查了输入的所有数据,并且所有数据都已定义。

checkUserPostData =   { "username" : registerUsername, "username_check" : 'true'};
        $http.post("server.php",
            checkUserPostData, {"headers" :
            { "Content-Type" : "application/x-www-form-urlencoded; charset=UTF-8" }} )

            .success(function(data, status, header, config){

               console.log(data);
                /*
                if(data=='exists')
                return true;
                else return false;*/

            })

        .error(function(data, status, header, config){
            console.log("error: "+data);
            return data;

        }); // end of $http request

    } // end of CheckUser()

以下是发送的ajax请求的chrome控制台日志:

Remote Address:::1:8080
Request URL:http://localhost:8080/app/server.php
Request Method:POST
Status Code:200 OK
Request Headersview source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:44
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Host:localhost:8080
Origin:http://localhost:8080
Referer:http://localhost:8080/app/
User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36
Form Dataview sourceview URL encoded
{"username":"asdsa","username_check":"true"}:
Response Headersview source
Connection:Keep-Alive
Content-Length:1231
Content-Type:text/html
Date:Tue, 27 May 2014 12:16:13 GMT
Keep-Alive:timeout=5, max=98
Server:Apache/2.4.4 (Win32) OpenSSL/0.9.8y PHP/5.4.16
X-Powered-By:PHP/5.4.16

0 个答案:

没有答案
相关问题