简体   繁体   中英

Return value false to stop ajax call?

var filterval = filterlist();
if (filterval) {
    $.ajax({
        type: "POST",
        url: "filt.php",
        data: main_string, 
        cache: false,
        dataType:'json',
        success: function(data) {}
    });
}

filterlist() {
    var fprice = $('input[name="fprice"]').val();
    var lprice = $('input[name="lprice"]').val();
    if (fprice >= lprice) {
        alert("Value Wrong");
        return false;
    }
    else if (fprice == "" || lprice == "") {
        alert("price empty");
        return false;
    }
    return fprice + " " + lprice;
}

I expectation is

  1. Filterlist() function value false to AJAX process stop.
  2. Value not false to work on ajax process .
 var fprice = parseInt($('input[name="fprice"]').val());
 var lprice = parseInt($('input[name="lprice"]').val());

Use parseInt to convert fprice and price into numbers(from strings) and then compairing is possible :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM