Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

POST请求不成功? #42

Closed
seekwe opened this issue Sep 6, 2015 · 9 comments
Closed

POST请求不成功? #42

seekwe opened this issue Sep 6, 2015 · 9 comments

Comments

@seekwe
Copy link

seekwe commented Sep 6, 2015

        var data = {name:this.name,phone:this.phone,num:this.xhr};
         console.log(data)
        this.$http.post('location.href, data,function (data, status, request) {


  }).error(function (data, status, request) {

  })

在php里 var_dump($_POST) == array(0) { } ?
应该是 array(3) { ["name"]=> string(2) "32" ["phone"]=> string(2) "23" ["num"]=> string(1) "0" }才对啊

@azamat-sharapov
Copy link

Please try to use english, especially on this repository, since it's not maintained by Evan 😄

@seekwe
Copy link
Author

seekwe commented Sep 8, 2015

Very strange,In PHP Can't get to POST data ,See code:
post data : {name:me,phone:10}
Output : var_dump($_POST) == array(0) { } ,
Normal should be: var_dump($_POST) == array(0) { ["name"]=> string(2) "me" ,["phone"]=>10} ,
Please forgive my English level is not good :

@azamat-sharapov
Copy link

There must be something wrong on JS code, you didn't post it complete, there is even syntax error:

this.$http.post('location.href, data,function (data, status, request) {

@seekwe
Copy link
Author

seekwe commented Sep 8, 2015

No error, the request was successful.
Is the server side to get POST data failure,

@azamat-sharapov
Copy link

you probably mean location.href, not 'location.href'.
Not sure what is wrong though.. have been using this with PHP also, without problems.
Double check your setup, they should be something wrong with it, not with vue-resource.

@seekwe
Copy link
Author

seekwe commented Sep 8, 2015

Excuse me, My carelessness,please don't tangle in location.href and 'location.href'.,
The problem is Server access to POST data,But Request Method is POST,So strange

@steffans
Copy link
Member

steffans commented Sep 8, 2015

@seekwe The post data is send JSON encoded, in order to decode it in PHP you need to do this:

$data = json_decode(file_get_contents('php://input'), true);
var_dump($data);

If you want to use the normal $_POST data you need to enable the emulateJSON option:

Vue.http.options.emulateJSON = true;

@steffans steffans closed this as completed Sep 8, 2015
@seekwe
Copy link
Author

seekwe commented Sep 8, 2015

thanks! The original is the problem of request payload :)

@smelike
Copy link

smelike commented Mar 29, 2017

what does it mean request payload.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants