bonez
bonez

Reputation: 695

Jquery form ajax call trouble

I'm having trouble submitting an ajax request.

I've tried to set it up pretty simply just to see if i can get a response

Here is my js:

$(document).ready(function() {
        $('#mainform').submit(function() {
                $.ajax({
                        type: "POST",
                        url: "processform_ajax.php",
                        data: $(this).serializeArray(),
                        dataType: "json",
                        sucess: function (data) {
                                alert("data" . data);
                                //$("#response").append(data);
                        },
                        error: function(error, txt) {
                                alert(error.status);
                        }
                }); 
       });
});

My php is simply this

<?php
        $errors = array ('a' => 'TEST!');
        echo json_encode($errors);
?>                                                                                                                                                              

When I try to run this with the firebug extension i'm seeing the post looks okay. (which it shouldn't matter at this point, because my php just echo's out something)

On the response side I'm seeing this error : NS_ERROR_NOT_AVAILABLE

Which leads me to believe it can't find processform_ajax.php, but when i've tried the absolute url in url: "" option above. I can also hit the the php script through the browser's address bar and get the json response

Any clues?

Thanks

Upvotes: 0

Views: 227

Answers (2)

limc
limc

Reputation: 40168

NS_ERROR_NOT_AVAILABLE seems like a Firefox "bug/feature" where it tries to submit the call twice.

Try this... add a return false in your code, like this:-

$(document).ready(function() {
        $('#mainform').submit(function() {
                $.ajax({
                    ...
                }); 

                return false;
       });
});

This way, once the form is submitted through your JS code, the return false will prevent your "Submit" button from submitting the same request again.

Upvotes: 1

ScottE
ScottE

Reputation: 21630

Is sucess a typo in your code, or just on SO?

Upvotes: 0

Related Questions