Aessandro
Aessandro

Reputation: 5761

validation with AJAX

The following jQuery validation works well, however there is sth wrong within the AJAX call as it return unsuccessful. Full code here http://jsfiddle.net/YJwsZ/6/

I am quite new with AJAX as well.

I would like the following to return successful:

// AJAX call
$.ajax({
    url:url_site,
    data : data,
    // dataType: 'json',
    type: 'post',
    success: function(r){
        if (r.success) {
            alert('success');
        }
        else {
            alert('unsuccessful');
        }
    }
});

Upvotes: 0

Views: 116

Answers (2)

mayrs
mayrs

Reputation: 2377

Try to rebuild your ajax call and add the success callback as a chained function. You also might want to create a little php script that actually answers your testcase. See the docs!

http://jsfiddle.net/VyFng/1/

$.ajax({
    url: url_site,
    data: data,
    // dataType: 'json',
    type: 'post',
}).done(function(data, textStatus, jqXHR) {
    alert(textStatus);
})
.fail(function(jqXHR, textStatus, errorThrown) {
    alert(textStatus);
})
.always(function(dataOrJqXHR, textStatus, jqXHRorErrorThrown) {
    alert('callback after ' + textStatus + ' callback has been completed');
});

Upvotes: 1

klewis
klewis

Reputation: 8350

It's probably unsuccessful because url_site is not setup correctly. Re-check your path to the file you are trying to connect to. Use an absolute path if you just can't get a relative location working for you.

Upvotes: 0

Related Questions