[dx] Posted June 20, 2009 Share Posted June 20, 2009 I hope this is right place to start topic about AJAX, othervise feel free to move topic in plase where it belongs.I have this in index.php file echo "<div id='trazi_res'></div>"; This is js.js var xmlhttpfunction trazi(vrijednost) { xmlhttp = GetXmlHttpObject(); if (xmlhttp==null) { alert("Vas browser ne podrzava AJAX. Pokusajte sa IE, Firefox..."); } var url = "trazi.php"; url = url+"?sta="+vrijednost; xmlhttp.onreadystatechanged = stateChanged; xmlhttp.open("GET", url, true); xmlhttp.send(null);}function GetXmlHttpObject() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } if (window.ActiveXObject) { return new ActiveXObject("Microsoft.XMLHTTP"); } return null;}function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("trazi_res").innerHTML = xmlhttp.responseText; }} and this is trazi.php <?PHPecho '<head><script type="text/javascript" src="js.js"></script><style type="text/css">/* <![CDATA[ */ @import url(style.css); /* ]]> */</style></head>';include "db.php";$sta = $_GET['sta'];$select_from = mysql_query("SELECT * FROM stanice WHERE naziv LIKE '%$sta%'");while($trazi = mysql_fetch_array($select_from)) { echo "<br />" . $trazi['naziv'];}?> What's wrong with this? :SI can't figure out where is the error but it won't work...Thanks Link to comment Share on other sites More sharing options...
[dx] Posted June 22, 2009 Author Share Posted June 22, 2009 Anything on this?Thanks Link to comment Share on other sites More sharing options...
Ingolme Posted June 22, 2009 Share Posted June 22, 2009 For all I know, there are no errors at all. You haven't explained what is not working right. Link to comment Share on other sites More sharing options...
[dx] Posted June 22, 2009 Author Share Posted June 22, 2009 Well, I have input box where I type something what I want search. And on the bottom of the page there's <div> where it must be shown. But if I type in input nothing is shown in <div> Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2009 Share Posted June 22, 2009 Are you getting any errors? You should be using Firebug to help debug, in addition to showing the errors you can look at the ajax request going out and check the response for errors from PHP. You can also have PHP put all of its errors in an error log instead of trying to print them.error_reporting(E_ALL);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);ini_set('display_errors', 0);That will put all errors in a file called error.log in the same directory. Link to comment Share on other sites More sharing options...
[dx] Posted June 23, 2009 Author Share Posted June 23, 2009 There were some small errors like undefined variable etc. but that is now solved, and still nothing showing.. :S Link to comment Share on other sites More sharing options...
justsomeguy Posted June 23, 2009 Share Posted June 23, 2009 Post all of the code that's involved, whatever you type in, whatever triggers the Javascript function, etc. If the trazi.php file is what Javascript is sending the request to, why do you have that returning a head section? Are you replacing the head on the parent page? Link to comment Share on other sites More sharing options...
[dx] Posted June 26, 2009 Author Share Posted June 26, 2009 I can attach my files if you want to test it Link to comment Share on other sites More sharing options...
justsomeguy Posted June 26, 2009 Share Posted June 26, 2009 You can if you want, I just want to see the HTML structure. You posted the Javascript and PHP, but not the HTML. I won't be able to test it without a database though. Link to comment Share on other sites More sharing options...
[dx] Posted June 26, 2009 Author Share Posted June 26, 2009 Now I've formated code like this function stateChange(target) { alert(http.status); if (http.readyState == 4) { var response = http.responseText; if (response) { document.getElementById(target).innerHTML = response; } } } Added "alert"And keep getting message "404" which means not found, but file is in same dir as js.js and index.php Link to comment Share on other sites More sharing options...
justsomeguy Posted June 26, 2009 Share Posted June 26, 2009 Use Firebug to look at the request, it will show you the full URL that it's looking for. Link to comment Share on other sites More sharing options...
[dx] Posted June 26, 2009 Author Share Posted June 26, 2009 Yeah, that was"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /trazi.php was not found on this server.</p>\n</body></html>\n" Link to comment Share on other sites More sharing options...
[dx] Posted June 26, 2009 Author Share Posted June 26, 2009 Well, ok. Now getting thisElement referenced by ID/NAME in the global scope. Use W3C standard document.getElementById() instead.[break on this error] undefinedjs.js (line 32)[Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://127.0.0.1/radio/js.js :: stateChange :: line 12" data: no][break on this error] alert(http.status);But, I'm using document.getElementById Link to comment Share on other sites More sharing options...
justsomeguy Posted June 26, 2009 Share Posted June 26, 2009 Did you change variable names? Can you post the current Javascript? Link to comment Share on other sites More sharing options...
[dx] Posted June 26, 2009 Author Share Posted June 26, 2009 function createRequestObject() { var req; if(window.XMLHttpRequest){ req = new XMLHttpRequest(); } else if(window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } else { alert('Vas browser ne podrzava AJAX, pokusajte sa Firefox, IE...'); } return req; } var http = createRequestObject(); function stateChange(target) { if (http.readyState == 4) { var response = http.responseText; if (response) { document.getElementById('target').innerHTML = response; } } } function trazi(vr) { http.open('get', "trazi.php?sta="+vr, true); http.onreadystatechange = function(){ stateChange('trazi_res'); } http.send(null);} js.js currently Link to comment Share on other sites More sharing options...
[dx] Posted June 28, 2009 Author Share Posted June 28, 2009 something bad here? Link to comment Share on other sites More sharing options...
Ingolme Posted June 28, 2009 Share Posted June 28, 2009 Since target is a variable, you have to take the quotes off it:document.getElementById('target').innerHTML = response; Link to comment Share on other sites More sharing options...
[dx] Posted June 28, 2009 Author Share Posted June 28, 2009 I've tried that before.With Firebug I'm getting errordocument.getElementById("target") is null Link to comment Share on other sites More sharing options...
Ingolme Posted June 28, 2009 Share Posted June 28, 2009 I've tried that before.With Firebug I'm getting errordocument.getElementById("target") is nullYou have to put it without quotation marks:document.getElementById(target).innerHTML = response; Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.