【发布时间】:2013-12-13 04:38:35
【问题描述】:
嗨,朋友们可以请任何人给我。我是本章的新手..我正在尝试从 PHP 获取 JSON 格式值,但是在运行时我得到了这个输出“SyntaxError: JSON.parse: unexpected characte”.. 我想我在 php 转换中犯了错误......请帮帮我的朋友
我的 .html 文件
<html>
<head>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<title>Display Page</title>
</head>
<body>
<button type='button' id='getdata'>GetData.</button>
<button type='button' id='get'>sample</button>
<script type='text/javascript'>
$('#get').click(function() {
alert("laksjdflk");
});
$(document).ready(function() {
$('#getdata').click(function() {
$.ajax({
url:'neww.php' ,
dataType:'json' ,
success:function(output_string) {
alert(output_string);
},
error:function(xhr,ajaxOptions,thrownError){
alert(xhr.statusText);
alert(thrownError);
}
});
});
});
</script>
</body>
</html>
生成php.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("androidlogin");
$sql=mysql_query("SELECT* FROM trysave");
$temp="";
$i=0;
while($row=mysql_fetch_assoc($sql)){
$temp=$row['stringss'];
$temp.=$row['integerr'];
$array[i]=$temp;
i++;
}
echo json_encode($array);// this will print the output in json
?>
【问题讨论】:
-
查看以下链接 [jquery-ajax-in-getting-json-value-from-php][1] [1]:stackoverflow.com/questions/19029703/…