Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS不发送任何post数据_Javascript_Ajax_Json_Angularjs_Xmlhttprequest - Fatal编程技术网

Javascript AngularJS不发送任何post数据

Javascript AngularJS不发送任何post数据,javascript,ajax,json,angularjs,xmlhttprequest,Javascript,Ajax,Json,Angularjs,Xmlhttprequest,我在angularjs中发送了一个AJAX post请求,但它没有发送任何内容,因为我在服务器端检查了到达的内容,该内容没有使用以下命令打印: print_r($_REQUEST); 但是,当我使用: print_r(json_decode(file_get_contents("php://input"))); 它可以工作,因为我知道数据是以JSON块而不是常规格式发送的 现在我已经知道了如何使用类似于jQuery的头来发送post数据,但是使用常规的$\u请求或$\u post,我在服务器

我在angularjs中发送了一个AJAX post请求,但它没有发送任何内容,因为我在服务器端检查了到达的内容,该内容没有使用以下命令打印:

print_r($_REQUEST);
但是,当我使用:

print_r(json_decode(file_get_contents("php://input")));
它可以工作,因为我知道数据是以JSON块而不是常规格式发送的

现在我已经知道了如何使用类似于jQuery的头来发送post数据,但是使用常规的
$\u请求
$\u 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()
以下是chrome控制台发送ajax请求的日志:

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

angularjs没有以“表单编码”格式将参数发送到服务器。有关解决问题的方法,请参阅(或该页上的另一种方法)。可能重复的