Tuesday, 20 August 2013

How can I properly run an ajax function?

How can I properly run an ajax function?

For some reason this won't show anything when I run this ajax call in my
html document. I have checked to make sure the php script returns a json
file, which it does. I also have include the most recent version of
jQuery...Am I supposed to be calling this function in someway to get it to
run?
<script type="text/javascript">
$(document).ready(function(){
var output = $('#output');
$.ajax({
url: 'http://mySite.com/test.php',
dataType: 'jsonp',
jsonp: 'jsoncallback',
timeout: 5000,
success: function(data, status){
$.each(data, function(i,item){
var landmark = '<h1>'+item.name+'</h1>'
+ '<p>'+item.info+'</p>';
output.append(landmark);
});
},
error: function(){
output.text('There was an error loading the data.');
}
});
</script>

No comments:

Post a Comment