Jan
Jan

Reputation: 16084

jQuery GET/POST callback function not responding

I have this HTML:

<a href="#" class="btn" id="checkit">Verfügbarkeit prüfen</a>


 $("#checkit").on('click', function (e) {
                e.preventDefault();
                var expected_slug = $('#user_slug').val();
                $.post("/myUrl", {slug: expected_slug}, function(data){
                    console.log(data);
                });
                console.log("bal");

Why is console.log(data) not fired? But console.log("bal") gets fired...

response is 200 and contains "true"

Upvotes: 0

Views: 58

Answers (2)

Nando
Nando

Reputation: 863

Use .done above jquery 1.5

$("#checkit").click(function() {

    var expected_slug = $('#user_slug').val();
    $.post("/myUrl", {slug: expected}).done(function(data) {
        console.log(data);
    });
    console.log("bal");

    return false;
});

Upvotes: 2

user2567536
user2567536

Reputation: 237

because you are not enclosing it with a <form> tag

specify action too in your $.post() by adding in the settings as type: POST or type: GET

Upvotes: 0

Related Questions