Show results from a php app using ajax
Is there a way to display the results from a php app using an ajax call.
PHP
- <?php require_once('related.php') ?>
<?php
$resp = simplexml_load_file($apicall);
if ($resp->ack == "Success") {
$results = '';
foreach($resp->searchResult->item as $item) {
$pic = $item->pictureURLLarge;
$link = $item->viewItemURL;
$title = $item->title;
$price = $item->sellingStatus->convertedCurrentPrice;
$results .= "<figure class='relative r_image_container c_image_container qv_container'><div class='relative m_bottom_15'><div><img class='c_image_1 tr_all' alt='' src=\"$pic\"'></div></div>
<figcaption class='t_align_c'><ul><li><a href='$link' class='second_font sc_hover'>$title</a></li><li class='m_bottom_7'><b class='color_light sc_hover fw_light d_inline'>$price</b></li></ul></figcaption></figure>";
}
}
else {
$results = "<h3>Oops! The request was not successful.";
}
?>
<?php echo $results?>
Here is my attempt but im stuck as to what to put in the data field.
- <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>ajax php test</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js" ></script>
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: 'POST',
url: 'getitemsineBaystores.php',
data: data,
dataType : 'json',
success: function (data){
$('#myresults').html(data);
alert("Successful");
}
});
});
</script>
</head>
<body>
<div id="myresults"></div>
</body>
</html>
Can anyone help me with this.
thanks