阿賈克斯單獨的數據我在做一個Ajax調用是這樣的:這些來自MySQL的
function myCall() {
var request = $.ajax({
url: "ajax.php",
type: "GET",
dataType: "html"
});
request.done(function(data) {
$("image").attr('src',data);
});
request.fail(function(jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
}
這是我的ajax.php:
<?php
$connection = mysql_connect ("",
"", "");
mysql_select_db("");
// QUERY NEW ONE
$myquery = "SELECT * FROM mytable ORDER BY rand() LIMIT 1";
$result = mysql_query($myquery);
while($row = mysql_fetch_object($result))
{
$currentid = "$row->id";
$currentname = "$row->name";
$currenturl = "$row->url";
$currentimage = "$row->image";
echo $currenturl,$currentnam, $currenturl,$currentimage;
}
mysql_close($connection);
?>
從Ajax調用我的數據變量現在包含所有在一次變量:
($currenturl,$currentnam, $currenturl,$currentimage)
我怎樣才能把它們分開,所以我可以做這樣的事情:
request.done(function(data) {
$("id").attr('src',data1);
$("name").attr('src',data2);
$("url").attr('src',data3);
$("image").attr('src',data4);
});
使用JSON ......... –
作爲初學者的關鍵詞像'json'對我來說沒有任何意義..也可以是一個serialkiller或一隻狗。無論如何,謝謝 –