I am not entirely sure where to post this but i have a sample code. I am trying to use ajax to get information from a php page. However, I think I am either doing something wrong with the php or AJAX (Mostly the ajax I'm guessing).
Sample php page called ip.php:
Sample ajax with html:PHP Code:$advert = array(
'ajax' => 'Hello world!',
'advert' => 'adverts'
);
echo json_encode($advert);
Any help would be wonderful.HTML Code:<!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" /> <title>Get Ping</title> <script src="../js/jquery.js"></script> <script> $(function(){ $.ajax({ url : 'ip.php', type : 'POST', data : data, dataType : 'json', success : function (result) { $('#check').text(result['ajax']) // "Hello world!" displayed }, error : function () { $('#check').text("error"); } }) }) </script> </head> <body> <div id="check"></div> </body> </html>
Thanks.



Reply With Quote

Bookmarks