user103675
user103675

Reputation: 15

Why doesn't jquery call the success handler in this case?

I have this code:

$.post( "/ankauf/", {
        "kunden_id" : 1,
        "products" : products,
        "full_price" : parseInt($('#totalPrice').text()),
        "_token" : $('meta[name="csrf-token"]').attr('content')
    },
    function( data ) {            
        toastr.success("Ankauf abgeschlossen", "OK!");
    }
);

Which fires an post request to my Server like I do it often in my Application.

Chrome shows this request like this:

Request Method:POST  
Status Code:200 OK  
Remote Address:192.168.178.80:1414  

And the response is shown like this:

Cache-Control:no-cache  
Connection:close  
Content-Type:application/json

Response content:  
array(7) {  
  ["product_id"]=>  
  string(1) "5"  
  ["paidprice"]=>  
  string(2) "85"  
  ["condition"]=>  
  string(8) "Sehr Gut"  
  ["ovp1"]=>  
  string(1) "0"  
  ["ovp2"]=>  
  string(1) "0"  
  ["ovp3"]=>  
  string(1) "0"  
  ["ovp4"]=>  
  string(1) "0"  
}  
{"full_price":"85","updated_at":"2016-06-27 14:01:55","created_at":"2016-06-27 14:01:55","id":73,"created_by_id":1,"customer_id":1}

So the Servers response looks like a valid JSON response and the http-code is 200 any Ideas why the success handler does not fire?

Upvotes: 0

Views: 43

Answers (1)

Quentin
Quentin

Reputation: 944202

This is valid JSON:

{"full_price":"85","updated_at":"2016-06-27 14:01:55","created_at":"2016-06-27 14:01:55","id":73,"created_by_id":1,"customer_id":1}

But this is not:

array(7) {
["product_id"]=>
string(1) "5"
["paidprice"]=>
string(2) "85"
["condition"]=>
string(8) "Sehr Gut"
["ovp1"]=>
string(1) "0"
["ovp2"]=>
string(1) "0"
["ovp3"]=>
string(1) "0"
["ovp4"]=>
string(1) "0"
}
{"full_price":"85","updated_at":"2016-06-27 14:01:55","created_at":"2016-06-27
14:01:55","id":73,"created_by_id":1,"customer_id":1}

It looks like the server is using PHP and there is a print_r before the statement that prints the JSON.

Upvotes: 5

Related Questions