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

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

WBOY
WBOYOriginal
2016-06-13 12:32:17866browse

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 />

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


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

Statement:
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