Passing variables with POST to another page with Jquery

后端 未结 4 1664
[愿得一人]
[愿得一人] 2021-01-11 21:24

I am relatively new to Jquery and I was wondering how would one post variables to another page and then redirect? I used ajax function, the redirect works fine, but no varia

4条回答
  •  孤街浪徒
    2021-01-11 21:57

    $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "LinkTagOut.aspx",
            dataType: "json",
            data: { id: 1 }, // or the string: 'id=1'
            complete:
            function () {
                window.location = "LinkTagOut.aspx";
            }
    
    });
    

    From the $.ajax documentation (data option):

    Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).

    Also, make sure to return false from the end of the submit handler (or whatever fires the ajax call) to ensure that a 'normal' redirect is not happening.

提交回复
热议问题