开发者

jQuery worked yesterday. Not anymore

开发者 https://www.devze.com 2022-12-17 00:01 出处:网络
Yeah, so I have NO CLUE what happened. I\'ve been writing an AJAX comment script and I got it working, except it doesn\'t work开发者_StackOverflow社区 anymore. I restored it from a backup just in case

Yeah, so I have NO CLUE what happened. I've been writing an AJAX comment script and I got it working, except it doesn't work开发者_StackOverflow社区 anymore. I restored it from a backup just in case I chaged anything, but no luck. It goes to the "action" of the form instead of the jQuery, even though I have return false; This leads me to believe that one of the following things is wrong: I'm not including the jQuery correctly (which I am) or I have a syntax error. Do you see anything?

$(document).ready(function() {

    $("#alert").hide();

    $('form').submit(function() {

        $("#alert").slideUp().delay(1000);
        name = $('input[name=name]').val();
        email = $('input[name=email]').val();
        timestamp = $('input[name=timestamp]').val();
        entry_title = $('input[name=entry_title]').val();
        message = $('textarea[name=message]').val();
        $.post("/scripts/ajax_comment.php", {comm_name:name, comm_email:email, comm_message:message, comm_timestamp:timestamp, comm_entry_title:entry_title}, function(data){

            switch(data) {
                case "invalid email" : $("#alert").val("").append("Invalid E-mail address.").slideDown();
                break;

                case "empty field" : $("#alert").val("").append("Make sure no fields are empty.").slideDown();
                break;

                case "error" : alert("error");
                break;

                default: $(data).appendTo("#messages").hide().slideDown().animate({ color: "#669900" }, 1000).animate({ color: "#000000" }, 1000); 
            }   
        });
        return false;
    });
}); 

SOLVED: The problem was the delay(1000);


I'm not really sure what you're doing here:

$("#alert").slideUp().delay(1000);

jQuery 1.4's $.delay() is suppose to precede an action, if I'm not mistaken. You might want to remove that or complete that line - whichever is correct for your project. I see no other problems that would prevent this from succeeding.


Do you have Javascript enabled on your browser? Do you see any error messages in the console? If you put an alert in the document ready handler is it triggered?


I don't now if this leads to an error, but shouldn't be the keys of the JSON string enwrapped in quotation marks (I guess they are strings)? Like:

{'comm_name':name, 
 'comm_email':email, 
 'comm_message':message, 
 'comm_timestamp':timestamp, 
 'comm_entry_title':entry_title}

If you use Firefox, install Firebug and check the console for error messages.... Firebug helps a lot when developing websites.

0

精彩评论

暂无评论...
验证码 换一张
取 消