Echojson_encode returns a json object, which is a string obtained at the front end, rather than a json object. the front end uses the code to submit and process subsequent results.
Function del (id) {if (confirm ('are you sure you want to delete this keyword? ') {$. Post ('. /keyword', {op: 'del', id: id}, function (result) {alert (result); // Normally, this part should display object: object, however, a string if (result. code! = 0) {alert ("deletion failed! ") ;}Else {location. reload ();}});}}
The server returns the result using the following code:
Echo json_encode (array ("code" => 0); exit;
Normally, the variable alert result at the front end should display the object: object, but the json string is displayed now.
Reply to discussion (solution)
$. Post ('./keyword', {op: 'Del', id: id}, function (result) {...}, 'json ');
Function del (id) {if (confirm ('are you sure you want to delete this keyword? ') {$. Post ('. /keyword', {op: 'del', id: id}, function (result) {alert (result); // Normally, this part should display object: object, however, a string if (result. code! = 0) {alert ("deletion failed! ") ;}Else {location. reload () ;}," json ");}}