简体   繁体   中英

Javascript: how to post the whole page?

Is it possible to post the whole html page to the server(assuming that the server can handle it)?

I'm trying to implement the following setup. The user makes some changes(the user selects some text, and this text is wrapped in <span> tags with some class) to html and submits the page. The server extracts some relevant changes from a page. Is this possible? Or I need to design some more complex scheme?

Well you need to do some Javascript magic to do this.

Normaly only Input elements are submitted.

In your case you need to use Javascript to read the DOM and convert that to HTML ( document.body.innerHTML might work ) and then either use Ajax to call the server or store the data in a textbox and submit the form from the script.

But the question is, to do the change, wrap a seletion in span, you already have a script doing this, could you just post the action, for example parent element + selection start and selection end, or possibly the entire text within the element to the server and have the server duplicate the action?

It is quite possible - document.getElementsByTagName('html')[0].innerHTML should get you the page's HTML, and XMLHttpRequest (AJAX) allows POST for sending data. Combining these two should get you the basic functionality.

What you wish to do is possible, but IMHO you need to take a different approach. Rather than trying to post the whole page back, you would be better off presenting all the content of the page inside an HTML form. Each of the elements can be styled using CSS so that they don't look like form fields, but they remain editable. You could also switch areas within from static HTML to a regular form looking element using Javascript.

Using AJAX techniques you can automatically post changes on blur rather than having to have the user 'Save' on each change.

PS Post method has no built-in transfer limitations: 1MB, 100MB or the entire Web. But usually there are some reasonable limits set on the server-side.

http://bytes.com/topic/javascript/answers/92044-size-limit-submit-using-post

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