开发者

Javascript: how to post the whole page?

开发者 https://www.devze.com 2023-02-07 21:07 出处:网络
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 sel开发者_StackOve

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 sel开发者_StackOverflowects 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?


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.


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?


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.


P.S. 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号