Reputation: 1257
what is the error here :
.done(function(data) {
var json = JSON.parse( data );
if(json['status'] === "success"){
//some processing
}
else {
alert( "error 2" );
}
})
I got the error message on: var json JSON.parse('('+data+')')
data is returned from a php script :
/*...............*/
$sql->execute();
$i = 0;
while($result = $sql->fetch(PDO::FETCH_ASSOC){
$response["affiliates"][i]["affiliate_name"] = $result["coupon_name"];
$response["affiliates"][i]["affiliate_id"] = $result["coupon_id"];
$i++;
}
$response["status"] = "success";
echo json_encode($response);
Upvotes: 0
Views: 30453
Reputation: 227
JSON format only use curly and squared braces. You shouldn't append parentheses.
Upvotes: 1
Reputation: 44376
Because it's wrong.
"(1)" (for example) is not a valid JSON string. Why are you pasting those parens on at all?
Upvotes: 2
Reputation: 5450
Look at the spec for JSON (easily understood version here: http://json.org/). There is nowhere that says that parenthesis are valid. ({"foo": true})
, for example will never parse. It may be eval
ed as it is valid javascript, but javascript is not JSON.
Upvotes: 4