开发者

whats wrong with this ajax function?

This is my ajax function and

$('#save_form_3').button({
    icons: {
        primary: "ui-icon-disk"
    }
})
.click(function (event) {
    if($('#guarantor_details').validate().form()){
    var form_3_data = $("#gu开发者_运维问答arantor_details").serialize();
    $.ajax({
            type: "POST",
            url: "insert.php",
            data: form_3_data,
            success: function(response, textStatus, xhr) {
                alert(response);
                if(response=="success"){
                    alert(response);
                }
            },
            error: function(xhr, textStatus, errorThrown) {

            }
    });     
    return false;       
    }
});

first alert gives me message "success" and second alert doesn't execute. seems like if condition not working under success function.

any idea why it doesn't?

im using jquery-1.6.2.min.js.

maybe problem in jquery 1.6.2 or am i doing something wrong?

Thanks

if($SQL_INSERT){
    echo "success";
}else{
    echo mysql_error(); 
} 

thats insert.php anyway

if($.trim(response)=="success") works


try removing any whitespaces/newlines outside the tags in your insert.php file.


Maybe you could use a simple regex?

Instead of response=="success", try /success/.test(response)

This will return true if success is anywhere in the response string.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜