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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.