Jump to content

Making this script work


almightyegg

Recommended Posts

I have a script that I went through in a tutorial except it left a few bits out...

 

function createRequestObject() { 

   var req; 

   if(window.XMLHttpRequest){ 
      // Firefox, Safari, Opera... 
      req = new XMLHttpRequest(); 
   } else if(window.ActiveXObject) { 
      // Internet Explorer 5+ 
      req = new ActiveXObject("Microsoft.XMLHTTP"); 
   } else { 
      // There is an error creating the object, 
      // just as an old browser is being used. 
      alert('Problem creating the XMLHttpRequest object'); 
   } 

   return req; 

}

   // Make the XMLHttpRequest object 
   var http = createRequestObject();

function sendRequest(act) { 

   // Open PHP script for requests 
   http.abort; 
   http.open('post', 'delete.php'); 
   http.setRequestHeader('Content-Type', 'application/x-www-form- 
      urlencoded'); 
   http.send('act='+act); 

}

   if(http.readyState == 4 && http.status == 200){ 

      // Text returned FROM the PHP script 
      var response = http.responseText; 

      if(response) { 
         // UPDATE ajaxTest content 
         document.getElementById("ajaxTest").innerHTML = response; 
      } 

   } 

} 

<input type="button" value="Send AJAX Request" id="sendButton"
   onClick="sendRequest('test1');" />

 

Basically, I'm a newbie to AJAX and JS so there are probably lots of errors here...

the script I want to execute (delete.php) is this:

<?
include 'db.php'; // Connect to DB
$email = $_COOKIE['email']; 
$password = $_COOKIE['password']; 

$sql = mysql_query("SELECT * FROM users WHERE email='$email' AND password='$password' AND activated='1'"); 
$mem = mysql_fetch_array($sql);

$id = $_GET['t'];
$f = $_GET['f'];
$deletepost = mysql_query("DELETE FROM topics WHERE id = '$id' and fid = '$f' LIMIT 1");
$delpos = mysql_query($deletepost);

?>

 

As you can see this requires two PHP variables...$t and $f, that go into a URL like so: delete.php?t=$t&f=$f what I need help with is getting this information into the AJAX script (I think it's the sendRequest() part)

 

anyway thanks in advance :)

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.