echo json_encode回到json对象,在前端获取到的却是字符串,而非json对象

WBOY
Release: 2016-06-13 11:41:37
Original
1005 people have browsed it

echo json_encode返回json对象,在前端获取到的却是字符串,而非json对象
前端使用一下代码提交并处理后续结果

<br />function del(id){<br />      if(confirm('确认要删除此关键字吗?')){<br />		$.post('./keyword',{ op:'del',id:id },function(result){<br />			alert(result); //正常这个部分应该显示的是object:object,但现在显示的是一个字符串<br />			if( result.code != 0 ){<br />				alert("删除失败!");<br />			}else{<br />				location.reload();<br />			}<br />		});<br />	}<br />}<br /><br />
Copy after login

服务端使用以下代码返回
<br />echo json_encode(array("code"=>0));<br />exit;<br />
Copy after login


正常情况下在前端alert result这个变量,应该显示的是object:object,可现在显示的却是这个json字符串。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template