944,133 Members | Top Members by Rank

Ad:
You are currently viewing page 1 of this multi-page discussion thread
Nov 11th, 2009
0

AJAX/Jquery Internet Explorer error

Expand Post »
Hi guys

I was wondering whether someone could help me with a slight issue I have. I'm trying to set up a quick poll using AJAX which all works fine when using Firefox but running into issues via IE.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $(function() {
  2. $('.error').hide();
  3. $(".button").click(function() {
  4. var userid = $("input#userid").val();
  5. var name = $('input[name=name]:checked').val();
  6.  
  7. var dataString = 'name='+ name + '&userid=' + userid;
  8.  
  9. $.ajax({
  10. type: "POST",
  11. url: "poll/process.php",
  12. data: dataString,
  13. success: function() {
  14. $('#weekly_poll').html("<div id='message'></div>");
  15. $('#message').html("<h2>Thanks for your vote!</h2>")
  16. .hide()
  17. .fadeIn(500, function() {
  18. $('#message');
  19. });
  20. }
  21. });
  22. return false;
  23. });
  24. });

The issue I'm having is that although the form is being processed OK with data being captured in the database, once the form is submitted, the above script just seems to stop the rest of the page from loading. This only happens on IE and it must be something to do with the success function but as I'm new to JavaScript I don't know what I'm doing wrong.

Can anyway help me please? I think it's something really simple and I'm just being stupid.

Many thanks for reading.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
calina is offline Offline
8 posts
since Nov 2009
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
I don't know why your specified a callback for the fadeIn, it doesn't appear to do anything. If you change success to the following, what happens ?
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. success: function() {
  2. $('#weekly_poll').html("<div id='message'></div>");
  3. $('#message').html("<h2>Thanks for your vote!</h2>").hide().fadeIn(500);
  4. }
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
Thanks for replying

Unfortunately still get the same problem Once the form is submitted, all code beneath the form disappears on IE.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
calina is offline Offline
8 posts
since Nov 2009
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
It's hard for me to test, without having the complete code (html and php), I can only guess at this point, because the code looks okay.
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
OK. Here's all the code for you:

HTML
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script language="JavaScript" type="text/javascript" src="jquery.js"></script>
  2. <script language="JavaScript" type="text/javascript" src="poll.js"></script>
  3.  
  4. .
  5. .
  6. .
  7. .
  8. .
  9. .
  10. .
  11. .
  12.  
  13. <div style="background-image: url(../images/poll_background_mid.gif); background-repeat: repeat-y; width: 510px;">
  14.  
  15. <div id="weekly_poll" style="padding: 5 0 0 20;">
  16. <form name="poll" action="">
  17.  
  18. <label for="name" id="name_label">Question 1? </font>
  19. <input type="hidden" name="userid" id="userid" value="<?echo $userid;?>"/>
  20. <div style="margin: 5 0 0 0;">
  21. <input type="radio" name="name" id="name" value="Yes" /> Yes
  22. </div>
  23. <div style="margin: 0 0 5 0;">
  24. <input type="radio" name="name" id="name" value="No" /> No
  25. </div>
  26.  
  27. <input type="submit" name="submit" class="button" id="submit_btn" value="Vote" />
  28. </form>
  29. </div>
  30.  
  31. </div>

PHP - poll/process.php
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. include("../include/session.php");
  2.  
  3. $userid = $_POST["userid"];
  4. $answer1 = $_POST["name"];
  5.  
  6. $querypoll = ( "INSERT INTO poll (UserID, Poll, Answer1) VALUES ('$userid','Question here','$answer1')");
  7.  
  8. $resultpoll = mysql_query($querypoll);

JS
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. $(function() {
  2. $('.error').hide();
  3. $(".button").click(function() {
  4. var userid = $("input#userid").val();
  5. var name = $('input[name=name]:checked').val();
  6.  
  7. var dataString = 'name='+ name + '&userid=' + userid;
  8.  
  9. $.ajax({
  10. type: "POST",
  11. url: "poll/process.php",
  12. data: dataString,
  13. success: function() {
  14. $('#weekly_poll').html("<div id='message'></div>");
  15. $('#message').html("<h2>Thanks for your vote!</h2>").hide().fadeIn(500);
  16. }
  17. });
  18. return false;
  19. });
  20. });

Is that everything you need? Many thanks for taking the time to help.
Last edited by calina; Nov 11th, 2009 at 9:36 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
calina is offline Offline
8 posts
since Nov 2009
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
I uploaded this to my server (saved it as index.php). Appears to be working in IE7 and IE8. Can you confirm ?

php Syntax (Toggle Plain Text)
  1. <div style="background-image: url(../images/poll_background_mid.gif); background-repeat: repeat-y; width: 510px;">
  2.  
  3. <div id="weekly_poll" style="padding: 5 0 0 20;">
  4. <form name="poll" action="">
  5.  
  6. <label for="name" id="name_label">Question 1? </font>
  7.  
  8. <input type="hidden" name="userid" id="userid" value="<?php echo $userid; ?>"/>
  9.  
  10. <div style="margin: 5 0 0 0;">
  11. <input type="radio" name="name" id="name" value="Yes" /> Yes
  12. </div>
  13.  
  14. <div style="margin: 0 0 5 0;">
  15. <input type="radio" name="name" id="name" value="No" /> No
  16. </div>
  17.  
  18. <input type="submit" name="submit" class="button" id="submit_btn" value="Vote" />
  19. </form>
  20. </div>
  21.  
  22. </div>
  23. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  24. <script>
  25. $(function() {
  26. $('.error').hide();
  27. $(".button").click(function() {
  28. var userid = $("input#userid").val();
  29. var name = $('input[name=name]:checked').val();
  30.  
  31. var dataString = 'name='+ name + '&userid=' + userid;
  32. alert(dataString);
  33.  
  34. $.ajax({
  35. type: "POST",
  36. url: "process.php",
  37. data: dataString,
  38. success: function() {
  39. $('#weekly_poll').html("<div id='message'></div>");
  40. $('#message').html("<h2>Thanks for your vote!</h2>").hide().fadeIn(500);
  41. }
  42. });
  43. return false;
  44. });
  45. });
  46. </script>
Last edited by pritaeas; Nov 11th, 2009 at 9:43 am.
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
I was testing it out on IE6 which is where the error still occurs
Reputation Points: 10
Solved Threads: 0
Newbie Poster
calina is offline Offline
8 posts
since Nov 2009
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
I only have IETester, which shows my code snippet is working in IE6 (http://www.pritaeas.net/public/daniweb/poll/).

Could it be another part of the code ?
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
I think I may have confused you a little :s

That has never been the issue... the form submits the data to be processed and the thank you message has always shown up. The problem is that the form is at the top of the page with html code below it. When the form gets submitted in IE (version 6 is the one I've tested on) everything below the thank you message disappears. Does that make it clearer for you?

Once again.. thanks for trying to help.
Last edited by calina; Nov 11th, 2009 at 10:41 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
calina is offline Offline
8 posts
since Nov 2009
Nov 11th, 2009
0
Re: AJAX/Jquery Internet Explorer error
I see, opera has the same problem, although I cannot explain it at this moment. I'll keep looking.
Sponsor
Featured Poster
Reputation Points: 557
Solved Threads: 735
Bite my shiny metal ass!
pritaeas is offline Offline
4,204 posts
since Jul 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: problem in linking pages in wordpress!!
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Context-free Feedback Form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC