Jquery submits form but does not fade my div
The title almost says it all. I have a jquery code i've written, im not good at it but this is what i achieved:
$("#myForm").submit(function(){
//alert($(this).serialize());
$.post("submit.php", $(this).serialize(), function(data){
if(data == success) {
$("#add_vote").fadeOut("fast");
$("#verification_sen开发者_如何学Got").fadeIn("fast");
$("#wrong").fadeOut("fast");
} else {
$("#wrong").fadeIn("fast");
}
});
return false;
});
The form gets submitted well but the fadeIn and fadeOut's I have does not work. Do anyone know why?
Verify what submit.php returns, and what is in data
.
if(data == success) {
This looks suspicious, did you meant if (data == "success") {
? (success
is a variable, probably undefined; "success"
is a string.)
What is success
in:
if(data == success) {
Maybe you mean:
if(data == "success") {
Or else you maybe have misunderstood the $.post
function?
$.post("submit.php", $(this).serialize(), function(data){
Lets break it up:
"submit.php" // the url (OK)
$(this).serialize() // The data (OK)
function(data){ // The callback on success
And its only a helper function for the $.ajax
method, Witch also have a error callback:
var ajaxObj = $.ajax({
type: 'POST',
url: "submit.php",
data: $(this).serialize()
});
ajaxObj.success(function(){
// Success
});
ajaxObj.error(function(){
// Error
});
精彩评论