ajax - how to load a jsp asynchronously using jquery? -


i have parent.jsp depends on set of other jsps (around 40 in number) have 40+ child jsps included in parent jsp. result page load of parent.jsp slow. trying load childx.jsps asynchronously solve time lag problem.

did search , found utility code online. tried this:

//async.js     (function($) {     $(function() {         $('[data-async-url]').each(function() {             var $this = $(this),                 url = $this.attr('data-async-url');             $.ajax({                 url: url,                 datatype: 'html',                 type: 'get',                 success: function(html) {                     $this.replacewith(html);                 }             });         });     }); })(jquery); 

in parent.jsp - add childx.jsps follows:

<div id="child1" data-async-url='/pages/child/one.jsp' /></div> <div id="child2" data-async-url='/pages/child/two.jsp' /></div>  

when try load parent.jsp - find following error in browser console:

> http://localhost:8080/pages/child/one.jsp 404 (not found)   > http://localhost:8080/pages/child/two.jsp 404 (not found) 

my project structure follows:

>     myproject >      | - webcontent >          | - script >              | - async.js >          | - pages >              | - child >                  | - one.jsp >                  | - two.jsp  >                  | - parentfolder >                       | - parent.jsp 

the relative path giving seems going wrong where. tried several combinations nothing seems work. highly appreciated.

also, correct specify datatype "html" when trying load "jsp". trying "jsp" datatype didnt work.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -