Reputation: 1070
i'm trying to get some data by 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);
and this is the php code returning the data
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;
but the result is this
<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>
it's returning the whole html while there's no html code in that php page at all it's just php codes to connect to the database and fetch data any help ?
Upvotes: 1
Views: 1868
Reputation: 625
Make Sure You didn't print the html in config file or constructor or something like that. I got the the same problem. Solution is to create separate file to handle the ajax request.
Upvotes: 0
Reputation: 1373
In ajax/getolinedata.php if you have html code or echo html code, it will return the HTML code too.
Try opening ajax/getolinedata.php directly on your browser. If you get HTML page, then the same will be sent to ajax request.
So, try echoing only information that is needed and you should be good.
Also don't forget to set response type in header. For example if you are returning json data, use:
header('Content-type: text/json');
Upvotes: 3