ohdang888 Posted March 28, 2008 Share Posted March 28, 2008 Hey. I want to create a button that would send data back to the server, would do a PHP query, and then would print that info without the page reloading. I'm confused. I've been told on another forum that its not possible, but isn't that what they are doing when you register for something and you can check to see if the user name already exists..... can any1 point me in the direction? Thanks. Link to comment https://forums.phpfreaks.com/topic/98407-php-inside-of-javascript/ Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 you are looking for AJAX. Link to comment https://forums.phpfreaks.com/topic/98407-php-inside-of-javascript/#findComment-503577 Share on other sites More sharing options...
ohdang888 Posted March 28, 2008 Author Share Posted March 28, 2008 thanks. i;ve got a question with AJAX though... does the file i call have to be under .asp ??? or can it be a .php file too??? Thanks. Link to comment https://forums.phpfreaks.com/topic/98407-php-inside-of-javascript/#findComment-503589 Share on other sites More sharing options...
BlueSkyIS Posted March 28, 2008 Share Posted March 28, 2008 either way. you're just using javascript to call the script (whatever kind it is) and retrieve the output. javascript doesn't know .asp from .php. Link to comment https://forums.phpfreaks.com/topic/98407-php-inside-of-javascript/#findComment-503602 Share on other sites More sharing options...
ohdang888 Posted March 28, 2008 Author Share Posted March 28, 2008 ok i;m having a lot of trouble with this... my code is below... But its refreshing the whole page. This code is on test.php, and whe i click submit, it just puts the url to : test.php?vote=test Any ideas? Thanks! <script type="text/javascript"> function ajaxFunction() { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.VoteForm.vote.value=xmlHttp.responseText; } } xmlHttp.open("POST","vote.php",true); xmlHttp.send(null); } </script> <form name="VoteForm" onsubmit="ajaxFunction();> vote: <input type="text" name="vote" /> <input type="submit" value="Submit" /><br /> </form> Link to comment https://forums.phpfreaks.com/topic/98407-php-inside-of-javascript/#findComment-503639 Share on other sites More sharing options...
ohdang888 Posted March 29, 2008 Author Share Posted March 29, 2008 anyone? Link to comment https://forums.phpfreaks.com/topic/98407-php-inside-of-javascript/#findComment-504333 Share on other sites More sharing options...
BlueSkyIS Posted March 29, 2008 Share Posted March 29, 2008 your onsubmit also needs to return false, or the form will submit: <FORM NAME='someform' ACTION='POST' onSubmit='ajaxFunction();return false;'> Link to comment https://forums.phpfreaks.com/topic/98407-php-inside-of-javascript/#findComment-504343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.