I am trying to get Ajax to work all day and this is my last hope, I did a simple test If I get a response, then xhr.status is 0 instead of 200, and xhr.responseText is undefinded. I say a simple (php file) that generates a json object, as my code is in the form (I tried to use $ .ajax, but this was not either help):
$ (function () {$. ('#checkin') (function () {var ajaxRequest; connection to = ajaxFunction (); function ajaxFunction () {var ajaxRequest;! // variables that Ajax Possible makes try {// Opera 8.0+, Firefox, Safari ajaxRequest = New XMLHttpRequest ();} Hold (E) {// Try Internet Explorer Browser {ajaxRequest = New ActiveXObject ("Msxml2. XMLHTTP "};} hold (e) {ajaxRequest = new ActiveXObject try {(" Microsoft.XMLHTTP ");} catch (e) {// something went wrong Warning (" Your browser broke! "); Return false ;}}} AjaxRequest.open ("GET", "places.php", true); // create a function that will receive the data sent from the server ajaxRequest.onreadystatechange = function {if (ajaxRequest.readyState == 4) {warning (console.error (ajaxRequest.status));}} ajaxRequest.send (zero);}})}}and my php file is as follows: < / P>
& lt; Php heade r ('content-type: application / jsan'); "SQLquery.php" is required; $ Places = new SQLquery; $ Places- & gt; Db_query ("SELECT * FROM places"); Echo json_encode ($ places- & gt; results); ? & Gt;
Any help would be greatly appreciated Thanx
here Using a simple implementation is jQuery $ .ajax () and json
Javascript:
function sendAjax () {// data you want to give to places.php var params = {'checkin': true}; // call agax = $ Type AJX ({url: '/places.php', 'GET', data: parameters, datatype: 'Jason'}); // Send it and say which function you will use to handle the / ajax.done (sendAjaxDone) response; } // Response function sendAjaxDone (feedback) {console.log (feedback); }
place.php
header ('Content Type: Application / Jason'); "SQLquery.php" is required; If ($ _GET ['checkin']) {$ places = new SQLquery; $ Places- & gt; Db_query ("SELECT * FROM places"); Echo json_encode ($ places- & gt; results); }
No comments:
Post a Comment