Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
bananaman
Indestructible


Calc Guru


Joined: 12 Sep 2005
Posts: 1124

Posted: 09 May 2009 11:59:20 am    Post subject:

I am trying to use jquery to make an ajax request to a server to validate some input. The validation requires me to make some weird database calls and need to be in a php file so I need the jquery post function. Here is my current code...

Code:
$('#submit').click(function() {
            var p = new Object();
            p['range'] = $('input[name="range"]').val();
            p['division'] = $('input[name="division"]').val();
            p['num_quizzes'] = $('input[name="num_quizzes"]').val();
            flag = true;
            $.post('joseph_ajax.php',p,function(data) {
               update = data.split('|');
               if (update[0]=='error') {
                  flag = false;
                  $('#error').html('<img style="vertical-align: middle;" src="images/'+update[0]+'.png" alt="" /> '+update[1]);
               }
            });
            alert(flag);
            return false;
         });

Apparently when $.post is called it creates a new thread. Even when update[0] equals error and it displays the error message on the screen, the alert is still true. This makes me think that it is creating a new thread and the code after the post gets executed before the callback function.

I want to only stop the form from submitting if an error is thrown, but I can't seem to think of how to do this. I have tried to make the form submit inside the post callback if update[0]!='error', but this didn't seem to work either. I'm about ready to pull out my hair on this one.

If you want to see it in action you can see it at test.ifcayouthonline.org/form_joseph.html
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement