AJAX Help

This is a discussion on "AJAX Help" within the JavaScript Forum section. This forum, and the thread "AJAX Help are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 15th, 2007, 21:49
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Exclamation AJAX Help

I'm using this code to delete a blog entry:
HTML: Select all
<script type="text/javascript">
function deleteB()
  {
  var del;
  try
    {
    // Firefox, Opera 8.0+, Safari
    del=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      del=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        del=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
        del.onreadystatechange=function()
      {
      if(del.readyState==4)
        {
        alert(del.responseText);
        }
      }
    del.open("GET","/admin/deleteblog.php?<?php $id = $_GET['id']; echo $id ?>",true);
    del.send(null);
  }


</script>
</head>
<?php include('pieces/nav.php'); ?>
<form name="delete">
<p><input type="submit" name="delete" onClick="deleteB();" value="DELETE!" /></p>
</form>
and on the PHP page:
PHP: Select all

<?php 
include('../library/corefiles/blog.php');
session_start();
if (
$chk->checkType() == 3) {
    
$id $_GET['id'];
    
blog->deletePost($id);
    echo 
$id.'Was Deleted';
    }
    
?>
All that happens is an empty alert is thrown when I click the button.
Help appreciated!
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 16th, 2007, 06:37
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: AJAX Help

Hi alex, using <?php ?> between script tags won't work as is taken as part of the javascript. You would need to use PHP to echo a javascript variable outside the tags or echo the entire script with php.

Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 16th, 2007, 06:50
alexgeek's Avatar
Moderator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,812
Blog Entries: 9
Thanks: 2
Thanked 2 Times in 2 Posts
Re: AJAX Help

Hi Rakuli, when I viewed the source it seemed to work just fine.
How would I echo the variable properly then though?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 16th, 2007, 07:04
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: AJAX Help

Try adding another level of validation

Code: Select all
if(del.readyState==4)
{
if (del.status == 200) // good response from server     
alert(del.responseText);
else
alert(del.statusText) // What happened?
}
You may also like to try changing the variable name away from 'del' as I *think* this is a javascript reserved word.

Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
What is Ajax? Daniel Other Programming Languages 17 Apr 4th, 2007 14:50
Ajax Messages (Ajax Demonstration) iMarc JavaScript Forum 1 Mar 21st, 2007 22:48
PHP AJAX HOW-TOs nuk PHP Forum 1 Jan 5th, 2007 15:29
CSS and AJAX magicmarc Web Page Design 7 Aug 6th, 2006 13:21
Ajax ciancomp JavaScript Forum 12 Jul 12th, 2006 07:13


All times are GMT. The time now is 11:07.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42