Hey guys just a quick question, my AJAX is working in FF and Opera just fine, As in it repeats the function whenever the button is clicked, but in IE the first click works, but then it doesn't repeat...

I've been searching around form some fixes, and found quite a lot but none of it seems to work [as you can see i've tried adding '.live' but still nothing], wondered if it was obvious to anyone what was wrong here?

Heres' the code:

<script type="text/javascript">
                        $(document).ready(function(){

                               $('#generate-quote').live('click', function(e) {
                                
                                        e.preventDefault();
                                        
                                        $.getJSON("generator.php?", {act: 'char_con'}, function(data){

                                                $(".quote").html(data);
                                        });
                                        
                                });    
                                
                        });	
</script>

This is currently at the top of my index.php, but the button to run this function is echoed by php which I feel may have something to do with it? I'm not sure?

Thank help appreciated,

ello.

Recommended Answers

All 9 Replies

"generator.php?"

What the ? char is for? Maybe there is a problem?

"generator.php?"

What the ? char is for? Maybe there is a problem?

That's there because whenever you call a php function the url reads 'www.website.com?act=something' I assumed you'd need to place the '?' there, but I've just tried it without it, it does work, but still the same problem persists.

Thanks for the reply though, but sadly no luck.

do you really need getJSON? maybe you can use just get or post to retrieve data?

Ello,

I would have to guess that the function is working fine but there's no variation in behaviour each time your "#generate-quote" element(s) are clicked.

  • The url is always "generator.php"
  • The data is aways {act: 'char_con'}
  • The callback function always sticks the response into ".quote" element(s).

Unless something else affects the response generated by "generator.php, or the elements matching ".quote" differ, then each time your $.getJSON... runs, it will do exactly the same thing; you will see change(s) to the UI only on first click.

Airshow

@Airshow

Thanks for the info, the 'generator.php' displays random quotes, so every time the function is run it is in fact random, but I understand what your saying. I'll have another fiddle around with it to see if I can get it working :)

@SPeed_FANat1c

I'm not too sure, this is the only method I've tried so far, and it does work for the most part but I'm really not sure of the other methods are available in this instance.

Thanks for the info guys, I'll try and figure it out and post back, if I know the codes fine I should be o.k finding a work around :)

Thanks,

pippin.

Ello,

Aha, that explains your code.

You might like to consider trying jQuery.ajax(...) which would allow explicit use of cache:false to ensure caching isn't an issue.

According to the jQuery API, the following is equivalent to getJason(...) :

$.ajax({
  url: url,
  cache: false, //added by me
  dataType: 'json',
  data: data,
  success: callback
});

Airshow

Ello,

Aha, that explains your code.

You might like to consider trying jQuery.ajax(...) which would allow explicit use of cache:false to ensure caching isn't an issue.

According to the jQuery API, the following is equivalent to getJason(...) :

$.ajax({
  url: url,
  cache: false, //added by me
  dataType: 'json',
  data: data,
  success: callback
});

Airshow

Aaa perfect! Thankyou worked great :)

Appreciate the help Airshow,

+1 for your efforts :)

:cool:

yeah, that stupid IE likes to cache data when we don't need to, I had problems also with that earlier. For that reason I always try to use post method for data sending to avoid problems with IE.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.