开发者

whats wrong with this ajax function?

开发者 https://www.devze.com 2023-03-20 06:00 出处:网络
This is my ajax function and $(\'#save_form_3\').button({ icons: { primary: \"ui-icon-disk\" } }) .click(function (event) {

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

精彩评论

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

关注公众号