Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery AJAX Success

Tags:

jquery

ajax

I'm using jQuery's $.ajax function to submit a form, which works, but the success is where I'm having my problem. Here is my code:

$("#form").submit(function () {
        $.ajax({
            type: "POST",
            url: '/login/spam',
            data: formData,
            success: function (dataCheck) {
                if (dataCheck == 'value') {
                     //Do stuff
                }
            }
        });
        return false;
    });

The problem I'm having is the if function keeps saying that dataCheck doesn't equal value. I know that it does, because when I remove return false; the page displays value, as expected. Also, I have used an almost identical code before, which works. Could somebody give me some advice?

like image 679
neex1233 Avatar asked Apr 22 '12 03:04

neex1233


People also ask

How check AJAX request is successful jQuery?

$. ajax({ url: "page. php", data: stuff, success: function(response){ console. log("success"); } });

Is AJAX successful deprecated?

ajax function is deprecated.

Is AJAX better than jQuery?

jQuery uses ajax for many of its functions, but it nothing else than a library that provides easier functionality. With jQuery you dont have to think about creating xml objects ect ect, everything is done for you, but with straight up javascript ajax you need to program every single step of the ajax call.

Is jQuery AJAX outdated?

Ajax (Asynchronous JavaScript and XML) is now long gone from the developer vernacular, along with other JavaScript technologies of that early Web 2.0 era. But jQuery has stood the test of time. Indeed, up till very recently, it was still growing year-over-year.


1 Answers

How to find the answer yourself:

Place a debug code to see what you get from the server.

$("#form").submit(function () {
        $.ajax({
            type: "POST",
            url: '/login/spam',
            data: formData,
            success: function (dataCheck) {
                console.log(dataCheck); // <==============================
                if (dataCheck == 'value') {
                     //Do stuff
                }
            }
        });
        return false;
    });

It will probably be in other format than you think.

like image 142
gdoron is supporting Monica Avatar answered Sep 19 '22 18:09

gdoron is supporting Monica