Saturday, 15 September 2012

javascript - SOLVED - Not getting a response on MDN AJAX example -


I used to first interact with PHP using AJX (for the first time using Javascript for any significant degree) Tried and did not get any success, so I tried to start the basics using a Mozilla Developer Network example as a test:

Example -

This or So it does not work, though I stick it directly by copying it from the site Only one change (setting URL on my test page, running on XAMPP) When I click on the button to run the MDN script, the resulting output is a problem with the "request" warning.

I am using Fayrbg for test results, and it displays a "200 OK" code to the position if I do not script I understand correctly, is it an error message needed?

The code from the example (with the code being used with the Foundation framework, this case is in any way):

   Doctype html & gt; & Lt; Html class = "no-js" lang = "en" & gt; & Lt; Top & gt; & Lt; Meta charset = "UTF-8" /> & Lt; Meta name = "viewport" content = "width = device-width, initial-scale = 1.0" /> & Lt; Title & gt; Foundation | Welcome & lt; / Title & gt; & Lt; Link rel = "stylesheet" href = "css / foundation.css" /> & Lt; Script src = "js / vendor / modernizr.js" & gt; & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Span id = "ajaxbutton" style = "cursor: indicator; text-decoration: underline" & gt; Request & lt; / Span & gt; & Lt; Script src = "js / vendor / jquery.js" & gt; & Lt; / Script & gt; & Lt; Script src = "js / foundation.min.js" & gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; (Function () {var httpRequest; document.getElementById ( "ajaxbutton"). Onclick = function () {makeRequest ( 'http: // localhost: 8000 / pages / test.html');}} function Mekandest (url) { If (window.XMLHttpRequest) {// Mozilla, Safari, ... httpRequest = new XMLHttpRequest ();} if (window.ActiveXObject) {// IE {httpRequest = new ActiveXObject ( "Msxml2.XMLHTTP");} catch (e) {httpRequest = new ActiveXObject ( "Microsoft.XMLHTTP");} catch (e) {}}} if (! HttpRequest) {alert ( 'Hoist :( can not create an XMLHTTP instance'); return false; } httpRequest.onreadystatechange = alertContents; httpRequest.open ( 'GET', url); httpRequest.send ();} function alerts the contents () {if (httpRequest.readyState === 4) {if (httpRequest.status == = 200) {Warning (ht tpRequest.responseText);} else had a problem with {alert ( 'request.');}}}}) (); & Lt; / script & gt; & Lt; / body & gt;  < / Pre> 

And here I have created the code for the test HTML page:

   doctype html> gt; & lt; html & gt; & Lt; Top & gt; & Lt; Meta charset = "UTF-8" & gt; & Lt; Title & gt; Untitled document & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; Test & lt; / Body & gt; & Lt; / Html & gt;  

Where am I going?

Edit - Referring to the basic PHP script I tried to use a modified version of the MDN script originally on it but could not get it working:

< Pre> & lt ;? Php required ('include / config.inc.php'); Requirement (MYSQL); $ U = Null; $ P = NULL; $ U = mysqli_real_escape_string ($ dbc, $ _GET ['username']); $ P = mysqli_real_escape_string ($ dbc, $ _GET ['password']); $ Q = "Select user from user where user name (user name = '$ U' and password = SHA1 ('$ p')) is active and"; $ R = mysqli_query ($ dbc, $ q) or trigger_error ("query: $ q \ n
MySQL error:". Mysqli_error ($ dbc)); If (@misschool_num_roose ($ r) == 1) {// a match was made $ A = 'true'; Print json_encode ($ a); } And {// no match was made $ A = 'false'; Print json_encode ($ a); }? & Gt; Second Editing - Thanks for the suggestion about console logs, this did what I needed to do to enable everyone and now it works fine.


No comments:

Post a Comment