我试图从一个带有ajax的php文件中获取更多值。
我的代码如下所示:
$.ajax({
type: "GET",
url: "phpfile.php",
success: function (value1,value2,value3,value4,value5,value6) {
$("#lga").html('<img src="' + value1 + '" alt="image" width="115" height="115"></src>');
$("#lg").text(value2);
$("#lgi").text(value3);
$("#lgv").text(value4);
$("#lgc").text(value5);
$("#lt").text(value6);
}
});
在php中我有6 echo
:
<?php
$game = fetchinfo("value","info","name","current_game");
$lastwinner = fetchinfo("userid","games","id",$game-1);
$winneravatar = fetchinfo("avatar","users","steamid",$lastwinner);
$chance = fetchinfo("percent","games","id",$game-1);
$items = fetchinfo("itemsnum","games","id",$game-1);
$ticket = fetchinfo("winticket","games","id",$game-1);
$value = round(fetchinfo("cost","games","id",$game-1),2);
$winnername = fetchinfo("winner","games","id",$game-1);
echo $winneravatar;
echo $game-1;
echo $items;
echo $value;
echo $chance;
echo round($ticket*100,7);
echo $winnername;
?>
答案 0 :(得分:2)
为什么不用ajax传递数组? 就像在PHP代码中创建一个数组,并以编码形式传递它,例如。
sudo arp -d <specific IP address>
比用html格式再次用echo json_encode($arrResult);
解析它。
例如。 ajax请求您参考
parseJSON()
在phpfile.php中,你的数组应该是
$.ajax({
type: "POST",
url: "phpfile.php",
}).done(function( msg ) {
//alert(msg);
msg = $.trim( msg );
if(msg != '[]'){
var obj = jQuery.parseJSON(msg);
$("#lga").html('');
$("#lg").text(obj.value2);
$("#lgi").text(obj.value3);
$("#lgv").text(obj.value4);
$("#lgc").text(obj.value5);
$("#lt").text(obj.value6);
}// if
});