Jump to content

php inside of javascript


ohdang888

Recommended Posts

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

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>

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.