A friend gave me the following piece of snippet:
json : { result: true }
success function(data){
if(data.result) {
//do something here
}
else {
//do something here
}
}
How would I integrate that code into the following code:
$(function() {
$("#action_button").click(function() {
var username = $("#username").val();
var password = $("#password").val();
var dataString = '&username=' + username + '&password=' + password;
if (username=='' || password=='') {
$('.success').fadeOut(200).hide();
$('.error').fadeOut(200).show();
}
else {
$.ajax({
type: "POST",
url: "processing/logsig.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
}
});
}
return false;
});
}
I'm returning JSON true or false values on the PHP side... Once the user inputs username and password, if the user is registered in the database, it logs him/her in. If the user isn't registered in the database, jQuery will load up a different form for the registration process.
success: function(){
. – Felix Kling Oct 20 '11 at 16:12