【发布时间】:2013-05-11 03:09:58
【问题描述】:
我正在尝试通过 ajax 获取一些数据
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 代码有什么帮助吗?
【问题讨论】:
-
您已将此标记为 jquery。你不会使用api.jquery.com/jQuery.ajax 来发出ajax 请求吗?
-
你为什么不使用 jauery.ajax ??
-
非常感谢大家帮助我,它已经解决了。
-
请使用答案前面的复选框将答案标记为已解决。
-
@jq 初学者尝试提及它是如何解决的或接受答案,以便对遇到相同问题的其他人有所帮助。干杯!