Ajax Talk - Asynchronous javascript and xml discussion board
 FAQ   Search    Usergroups      Register   Profile   Check your messages   Log in 
Signup now to enjoy a range of free membership advantages !!
Ajax Talk - Moderators Wanted
Beginner Ajax Questions

 
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help
View previous topic :: View next topic  
Author Message
Alberto
New one
New one


Joined: 28 Aug 2006
Posts: 2

PostPosted: Mon Aug 28, 2006 12:08 pm    Post subject: Beginner Ajax Questions Reply with quote

hi,

I read a book about ajax just couple days ago and now when I try to use it I have some problems such as;

I have a link in my page and what I want to do is, when I click to the link it changes status attribute's value from database to Y or N. If value is Y then change to N, if N then change to Y.

It works perfect for the first click.It changes the value once, but when I click second time it doesn't change anything.I have to open the page in a new window to use the link again. Sad

here is the test.html page
Code:

<head>
<script language="javascript">
var XMLHttpRequestObject=false;
var url;

if(window.XMLHttpRequest){
   XMLHttpRequestObject=new XMLHttpRequest();
} else if(window.ActiveXObject){
   XMLHttpRequestObject=new ActiveXObject("Microsoft.XMLHTTP");
}
function changeStatus(data_id){
   if(XMLHttpRequestObject){
   url="test.php?data_id=" + data_id;
   XMLHttpRequestObject.open("GET",url);
   XMLHttpRequestObject.onreadystatechange = function(){
         if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200){
         document.getElementById("testDIV").innerHTML = XMLHttpRequestObject.responseText;
         }
      }
   XMLHttpRequestObject.send(null);
   }
}
function test(div_id){
document.getElementById("testDIV").innerHTML = "test" + div_id;
}
</script>
</head>

<body>
<a href="#" onclick="changeStatus('1');">Link1</a>
<div id=testDIV>Text here</div>
</body>


and here is the php code
Code:

$data_id=$_REQUEST['data_id'];
$firstQuery="SELECT status FROM test WHERE id=$data_id";
$checkStatus=mysql_query($firstQuery);
$getStatus= mysql_result($checkStatus,0,0);
if($getStatus=='Y'){
$query="UPDATE test SET status='N' WHERE id=$data_id";
print "Status is N now";
} else if ($getStatus=='N'){
$query="UPDATE test SET status='Y' WHERE id=$data_id";
print "Status is Y now";
}

mysql_query($query);



And the other question is, how can I change the background color of a table cell?

thanks a lot
________
easy vape vaporizer


Last edited by Alberto on Tue Feb 01, 2011 12:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
Snyke
Forum Assistant
Forum Assistant


Joined: 20 Jun 2006
Posts: 87
Location: Zurich

PostPosted: Mon Aug 28, 2006 6:02 pm    Post subject: Reply with quote

OK the second question is easier to answer:
Code:
document.getElementById('id').style.background_color = "somecolor";
Where somecolor can be anything from the CSS Standard (hex or named colors).

The first question is a bit tough and I can't understand why. What browser has this been tested with? And did you call the script from your browser to see what happens (just paste the URL that would be requested by the XHR-Call in the location bar and see what happens).
_________________
[::[ Snyke.net ]::]
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Alberto
New one
New one


Joined: 28 Aug 2006
Posts: 2

PostPosted: Tue Aug 29, 2006 7:57 am    Post subject: solved! thank you very much! Reply with quote

Problem solved guys thank you very much. The reason for the first was about page catching! I just call the same URL with different URL some thing lile that;

test.php?id=1&rnum=same_random_number_here
________
Discovery


Last edited by Alberto on Tue Feb 01, 2011 12:25 pm; edited 1 time in total
Back to top
View user's profile Send private message
rey
Light Frequent Poster
Light Frequent Poster


Joined: 22 Aug 2006
Posts: 7

PostPosted: Thu Aug 31, 2006 2:20 am    Post subject: Reply with quote

You beat me to it! Smile

I was going to mention that it was cached and suggest something like this for the end of your URL string:

+ "?foo=" + new Date().getTime();

Glad to see its working.

Rey
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Ajaxtalk.com Forum Index -> AJAX Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
 Advertisements
 XML & Copyright Notice 
    


Powered by phpBB © 2001, 2005 phpBB Group

What is according to Wikipedia: Ajax Web2.0 XML E4X


Link to our site:

  


del.icio.us digg spurl wists simpy newsvine blinklist furl blogmarks yahoo! myweb smarking ma.gnolia segnalo reddit fark technorati cosmos


Normal Bookmark


Partner Button Links:
Codecrunch.com: Webmaster Tutorials    One Ajax


Partner Text Links:
quomon | web20log | ajaxmatters | tableless | 456bereastreet | music charts | gift ideas | competitions | free xbox 360 | link trade ?


Credits:
it consultancy & project management lead generation zoekmachine optimalisatie steal these buttons seo expert