Victor Kimura
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(fu nction() {
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.user name);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log(textStatus);
}
});
}
What's wrong with the code?
test.php
init.js
test-ajax-call.php
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(fu
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
},
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! yeah, I changed the submit to a regular button.