Link to home
Start Free TrialLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

what's wrong with simple ajax call?

Hi,

I was just testing Google chrome debugger and I have this simple code to test an ajax call but  the ajax call is returning an error. The textStatus just states "error" and I tried to look at the console and it's blank. The username is being passed and the json is returning from the called php file "test_ajax_call.php" but the I guess something is wrong with this part:

$(document).ready(function() {
    $('#submit_form').click(function() {
        submit(); //check if username/email exists already
    });

});

function submit() {
    var username = $("#username").val();

    $.ajax({
        type : 'POST',
        url:'test_ajax_call.php',
        dataType: 'json',
        data: {
            username : username
        },
        success: function(data) {
            $("div#ret_username").text(data.username);
        },
        error: function(XMLHttpRequest, textStatus, errorThrown) {
            console.log(textStatus);
        }
    });
}

What's wrong with the code?
test.php
init.js
test-ajax-call.php
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Victor Kimura

ASKER

Hi Leaking971,

Thank you! yeah, I changed the submit to a regular button.