简体   繁体   中英

Parse data before sending it to action link or artificial POST request

I have a form and it have action="http://anotherhost.com" . But I have a problem, before sending it to another host I need to save entered data to database and here is a problem, how to do it?

I have idea, but don't know how to realise it.
1) Change action="http://anotherhost.com" to my site, parse entered data and add into database, but then after this I need to simulate artificial POST request to another host.
2) First parse it with JS (AJAX) and after parsing it, let to send form to another host.

Your second option is probably the best way to go, something like this should work!

http://jsfiddle.net/7Sq3J/

$('form').submit(function(event) {
    $.post('http://example.net/', $('form').serialize(), function(data){
        // handle returned data in here
    });
});

This will use a POST request, and send everything you send in the form to http://example.net/

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