简体   繁体   中英

jquery post without ajax or form

Is there a way in jquery to submit a post without a form. like can I use the function $.post("script.php",{var1:"abc", var2: "cde"}) such that it will not run on the background but instead post and redirect the page to script.php file as if var1 and var2 were submitted via a form.

You can execute ajax request and make redirect to url when the response comes.

$.post("script.php",{var1:"abc", var2: "cde"},
    function(data) {
        if (data.success) {
            window.location.href = data.redirectTo;
        }

    }
)

in this case response from script.php should looks like {success:true, redirectTo: "newUrl.php"}

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