Jump to content

Urgent - Something Causes An Error


denny911

Recommended Posts

Hello to all,Here's the link to my site: www.poslovni-adresar.baI decided to set up a small section for displaying several inputs from my databaseI tried to implement simple AJAX page to do the job (i slightly changed w3schools ajax mysql+php example to suit my needs)On my LOCALHOST everything works just fine (FF 3.0, IE7 and IE8) but it made me quite disappointedwhen i noticed it doesn't work on my web serverIt seems this part of the code is the problem:

while($row = mysql_fetch_array($result)) {	print '<div class="subjekt"><a onclick="showUser(\'' . $row['f_id'] . '\')">';	print substr($row['_F_IME'],0,30) . '</a>';		if(strlen($row['_F_IME']) > 30 )			 print ' ...';	print '</div>';}

the part in parenthesis after showUser: showUser('12345') seems to cause the problem.the difference between my code and tutorial's code is that tutorial contains example with form drop downand action is triggered via onChange event. since i wanted to use text link, i didn't know what to use besideonclick event. maybe there should be something else?i tried adding href="#" but it doesn't solve anythingalso, adding "return" before showUser does nothinghow is it possible for this to work on my localhost and to NOT WORK on my web server?Thanks in advance

Link to comment
Share on other sites

Don't you have to escape the double quotes?

Link to comment
Share on other sites

Don't you have to escape the double quotes?
dont think sonotice single quotes on the beginning, after "print", so that does not interfere with doublequotes and therefore they dont have to be escapedIf im wrong, someone correct mebesides, everything works on localhost
Link to comment
Share on other sites

A weird thing indeed.

Link to comment
Share on other sites

Try to remove everything between the showUser() function and see what happens.

Link to comment
Share on other sites

Try to remove everything between the showUser() function and see what happens.
hmm, that f_id is the argument needed by AJAX page (there's an sql query that isexpecting it via $_GET variable, to know what rows to serve)dont think anything beside what's already happening (and that's links not working)would happen.I wonder whether there is a way to send that parameter (id number) using onclickevent - that is, what is the correct way to form a link
Link to comment
Share on other sites

I glanced at the generated code at the link you provided, and the function call looks fine. (Though, as you pointed out, adding return or javascript: is just pointless.) When I click on the link, my Firefox Error Console says that showUser() is not defined. I looked in all the scripts you load, and I couldn't find it. So maybe you forgot to connect to the script that contains that function.Firefox Error Console also shows A LOT of CSS errors.You really should be testing in Firefox and using the Error Console. It's a huge time saver.

Link to comment
Share on other sites

I glanced at the generated code at the link you provided, and the function call looks fine. (Though, as you pointed out, adding return or javascript: is just pointless.) When I click on the link, my Firefox Error Console says that showUser() is not defined. I looked in all the scripts you load, and I couldn't find it. So maybe you forgot to connect to the script that contains that function.Firefox Error Console also shows A LOT of CSS errors.You really should be testing in Firefox and using the Error Console. It's a huge time saver.
i'm not experienced with javascript nor with the error consolewell, if showUser() not being defined is the case, how do you explain everything working onmy localhost? is that normal?this is showUser.js script:
var xmlHttp;function showUser(str){ xmlHttp=GetXmlHttpObject();if (xmlHttp==null) { alert ("Browser ne podrzava HTTP Request"); return; }var url="ajax/subjektiTop.php";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=stateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null);}function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {  document.getElementById("txtHint").innerHTML=xmlHttp.responseText; } }function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { //Internet Explorer try  {  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  } catch (e)  {  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  } }return xmlHttp;}

Link to comment
Share on other sites

my friend, thanks for the effort you put in thissuddenly, the damned thing works in FF but still shows error and doesnt work in IE7 (probably IE6 too)i was messing something about paths (after your posts i became suspicious about them) and somehow fixed it for FFcan you repeat the same as previous now and tell me if there's any difference now (what can you tell me about showUser.js now)thanks

Link to comment
Share on other sites

It is the same as before. I get the same error.What I would expect is a file in your scripts directory called showUser.jsAnd I would expect a line in your document that looks like this:<script src="/scripts/showUser.js" type="text/javascript"></script>I don't find either of these things.

Link to comment
Share on other sites

well, i should've known from the start, it was pretty much obvious that the problem wasrelated to paths. one more reason for that was the fact that this worked on my localhostand not on my web server (probably the two have different settings for paths)i carefully inspected everything, put my ajax served PHP file in the root (to avoid trickypath setting), and that solved the problem finally (at least, seems to be so)thank you for your help and pointing out what you've noticed. that's been very helpful!have a nice day,regards from bosnia h.// Denis

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...