我試圖通過Ajax來獲取一些數據provlem與阿賈克斯全部退回HTML代碼
var ajax1 = false;
ajax1 = new XMLHttpRequest();
ajax1.open("GET","ajax/getolinedata.php");
ajax1.onreadystatechange = function(){
var mylink = ajax1.responseText;
$("a[goal='online']").attr("href",mylink);
}
ajax1.send(null);
,這是PHP代碼返回數據
while($cartRow = mysql_fetch_array($getCartR)){
$pro_name = $cartRow['Product_Name'];
if(strstr($pro_name," ")){
$pro_name = str_replace(" ","_",$cartRow['Product_Name']);
}
$lin .= "&li_".$x."_type=product&li_".$x."_price=".$cartRow['Product_Price']."&li_".$x."_quantity=".$cartRow['Quantity']."&li_".$x."_name=".$pro_name."&li_".$x."_tangible=N";
$x++;
}
echo $lin;
但結果是這
<a href="<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body></body></html>https://www.2checkout.com/checkout/purchase?sid=123456&mode=2CO&li_0_type=product&li_0_price=3700&li_0_quantity=1&li_0_name=iphone_4&li_0_tangible=N&li_1_type=product&li_1_price=3000&li_1_quantity=1&li_1_name=Lumia_720&li_1_tangible=N&li_2_type=product&li_2_price=4500&li_2_quantity=1&li_2_name=ipad_2&li_2_tangible=N&li_3_type=product&li_3_price=2000&li_3_quantity=2&li_3_name=Lumia_520&li_3_tangible=N" goal="online"><img src="images/online.jpg"></a>
它返回的是整個html,而該php頁面中沒有html代碼,它只是連接到數據庫的php代碼e並獲取數據的任何幫助?
您已將此標籤標記爲jquery。你會不會使用http://api.jquery.com/jQuery.ajax/發出ajax請求? – slinky2000
你爲什麼不使用jauery.ajax? – bipen
非常感謝你們全部幫助我解決了問題。 –