简体   繁体   中英

Save html-page to MySQL DB after being modified with javascript

I want to save an entire HTML-page after it's being modified with Javascript. It's a week schedule, written by my predecessor, that has to be saved per user in a MySQL Database. I've been searching on this topic for hours but haven't found anything useful.

Does anyone have a clue if this is possible? And if so, how this can be done easily?

Obtain the source from the DOM with javascript:

document.getElementsByTagName('html')[0].innerHTML

Then send an Ajax request to your PHP script that stores the value into the database:

var formData = new FormData();
formData.append("html", document.getElementsByTagName('html')[0].innerHTML);

var oXHR = new XMLHttpRequest();
oXHR.open("POST", "http://foo.com/saveHTML.php");
oXHR.send(formData);

In your PHP script:

$html = $_POST['html'];
... # store it

You can get actual page HTML with Javascript:

var html = document.getElementsByTagName('html')[0].innerHTML

And then make a POST request to serverside script which will save that page to database.

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