开发者

jquery clearing $.post data

I'm building a multi-part form. Each part executes a new script. When each script is executed it will check for required data. If said data is missing it will return a string "false"

part 1 fails correctly (calls highlight()) but part 2 just spits out "false" bypassing the highlight function as if data !== false. I've tried clearing data but this does not seem to work. Any ideas?

Thanks

    $('.submit').live('click', function(){
    var bclick = $(this);   
    var frm = "../../scripts/retain-" + $(this).attr('rel') + ".php";
    var fields = $('#retain-form').serialize();

    $.post(frm, fields, function(data){
        if(data == 'false'){
            hig开发者_如何学JAVAhlight();
            data = '';
        }else{
            var nForm = $(bclick).attr('rel');
            nForm = parseInt(nForm[4]) + 1;
            $(bclick).attr('rel', "form" + nForm);
            $('#retain-steps').html(data);
        }
    });
})


Your highlight function should receive a bclick param

function highlight(bclick){
 ...
}

and be called like this:

highlight(bclick);

You should pass the bclick param to your highlight function, so it can know which part to highlight.

Cheers


I'm not entirely clear on what you're trying to do and what's going wrong here, but one thing to be careful with is using the type coercing == comparison around JavaScript's "falsy" values. Since "" == false, you run into some unintuitive bugs around that. Try using the strict === comparison in your conditionals instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜