hey there i have this jquery combined with ajax:
var username = $("#username").val();
if(username){
$.ajax({
url: 'check.php',
data: {data: JSON.stringify(username)},
type: 'POST',
dataType: "json",
success: function (data) {
if(data.result == 1) {
var name = "content"; // SAFE anything in global variable?
}
}
});
} else {
alertify.error( "You forgot to type your username" );
}
if(name) {
// if global variable is set => do something
} else {
// if not => do something else
}
i want to check if the data.result = 1, and thats the only way i could imagine to find out if data.result returned is 1.
EDIT:
I dont want to check it via alert, because i will need to work with this global variable later, anybody could help me with my problem? greetings
EDIT :
$(document).ready(function(){
$("#submitto").submit(function(e){
e.preventDefault();
var username = $("#username").val();
var name;
if(username){
$.ajax({
url: 'check.php',
data: {data: JSON.stringify(username)},
type: 'POST',
dataType: "json",
success: function (data) {
if(data.result == 1) {
name = "content";
}
}
});
} else {
alertify.error( "You forgot to type your username" );
}
if(name) {
alert("ok")
} else {
alert("not ok")
}
});
});