How to prevent form element from sending some fields we don't want?

后端 未结 3 1768
自闭症患者
自闭症患者 2020-11-30 10:35

I have a form element that contains about 5 fields which final query is going to create by processing values those fields. So I want to send only final query, not all of tho

3条回答
  •  孤街浪徒
    2020-11-30 11:19

    I think the best solution is to handle the submit and then send the request yourself:

    $(form).submit(function() {
        //do everything you need in here to get the final result
        var finalResult = alotoflogic();
        $.get("abc/def.aspx",final=finalResult, "callbackfunction", "responseType");
        return false;
    });
    

    that should do exactly what you want. EDIT: as Alex pointed out this solution wouldnt send you to that page, just get the results if you need to go to the new page you can do:

    $(form).submit(function() {
        //do everything you need in here to get the final result
        var finalResult = alotoflogic();
        window.location('abc/def.aspx?final='+finalResult);
        return false;
    });
    

    This way the browser is redirected to that page and only the final result is send.

提交回复
热议问题