javascript - Handling an AJAX response as a document? -


i'm trying implement ajax shebang - meaning example.com/#!/somepage.php example.com/somepage.php loaded content area of ajax site.

the obvious way of doing request somepage.php , replace entire contents of documentelement new document. seems kind of defeat purpose of ajax.

instead, i'm thinking of trying load somepage.php, , extracting content part of page , put in content area.

to this, could use regex /<div id="content">.*</div>/ bad idea (the simplest problem being "which </div> ends content?). instead, i'd able ajaxresponse.getelementbyid('content'), how go converting ajaxresponse document (or documentfragment) object?

or wrong approach implementing such ajax setup? better off having server side check x-requested-with: xmlhttprequest , send content area?

instead of requesting #!'d page verbatim, request variant compatible #! handler.

this approach takes 2 steps.

  1. expose content pages via json. make service available requests satisfy particular condition, such special parameter, extension, header, etc. example, /somepage.php?json might serve content of /somepage.php in json.

  2. write #! handler when handles request, calls upon service defined above page. example, when example.com/#!/somepage.php loaded , handle somepage.php, request somepage.php?json instead, , propagate content of request appropriate.

this approach affords number of benefits.

  • reduced response size of ajax request
  • reduced server-side load, since no html need rendered
  • avoids html parsing , expensive dom manipulation
  • no dependence on browser send appropriate ajax-related headers

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -