Jump to content

PHP and AJAX Problem.


Mod-Jay

Recommended Posts

Im trying to make an AJAX button to load a php code. I dont know whats wrong with it atm. Could you take a look at the code and try to help?

 

Ajax:

function MakeRequest()
{
  var xmlHttp = getXMLHttp();
  
  xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      HandleResponse(xmlHttp.responseText);
    }
  }
  
  document.savecode.submit();
  xmlHttp.open("GET", "edit.php?save=true", true); 
  xmlHttp.send(null);
}

function getXMLHttp()
{
  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;
      }
    }
  }
  
  function HandleResponse(response)
{
  document.getElementById('SavedFile').innerHTML = response;
}
  

 

PHP:

<?php
echo "<input type='submit' onClick=\"document.savecode.submit();\" name='submit' value='Save code' />";
echo "<form name='savecode' action='edit.php?save=true' method='POST' ><textarea id=\"code\" name='code' rows=\"*\" cols=\"*\">" .htmlspecialchars($contents) . "</textarea>";
echo "<input type='hidden' value='$page' name='page' id='page'/>";
echo "</form>";
?>
<div id="SavedFile">
</div>

Link to comment
https://forums.phpfreaks.com/topic/235783-php-and-ajax-problem/
Share on other sites

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.