javascript problem
Archived from the Xataface Users forum.
samhans — Fri Mar 09, 2012 5:30 am
hai Steve and all;
i have made a page which without refreshing shows the search result from database.
for that i have made a html form with javascript . i have tested it and it is working.
outside xataface .
the exact code is like this:
< html>
<script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send(); } </script> <form> <select name="users" onchange="showUser(this.value)"> </select> </form></html>
this form onchange call the javascript and the javascript calls a getuser.php file which query the database and shows the result as a table.
i have tested it and its working. but i failed to integrate it with xataface main templates.
to integrate i have made a search.html form in templates folder and a action to show the templates as default as we make dashboard. i have included the javascript my application delegate class get included.
but when i am selecting the name in search page nothing happens . hopefully i think the javascript is not called at all. please help me to say where i am wrong.
thanks in advance
shannah — Fri Mar 09, 2012 10:34 am
Hard to comment with this amount of information. Troubleshooting Javascript involves:
- Checking your javascript error log and following clues.
- Reviewing the resulting Page source to see that the javascript is actually included.
- Adding messages in javascript at various points to see what code is executing (e.g. using console.log() if you are using chrome, safari, or Firefox - or just alert() otherwise).
-Steve
samhans — Fri Mar 09, 2012 10:43 am
Steve the code is ok i have checked it and its working. please check the xmlhttp.open tag in my javascript. is this will work in xataface
shannah — Fri Mar 09, 2012 10:49 am
Anything that will work outside Xataface will work inside Xataface.
You just have to be aware of your context and environment.
samhans — Fri Mar 09, 2012 10:53 am
Steve can i included javascript inside the macro tag in my search html template.