Tuesday 15 September 2015

how to execute function under jquery chunk -


I have to use the $ post function several times in the page. Apart from this, I have to use the data returned from the post method for filtering purpose. That's why I put such a post function:

  $ (document) .ready (function () {function loadData (url) {$ .post (url, function) {var $ Data = data;})}} raw = load data (page 01.php) .Filter ("# id"). Html (); $ ("# content"). Html (raw); var raw = load data (page 02.fpp) .filter ("#otherId") .HTML (); $ ("# content2") .html (raw);});   

but it is not working Any work to modify the code above will be appreciated for working. Regards

You magical after your function in jquery loadData (like jquery loadData) Can not call any other way 'Page02.php'). Your function needs to return the jQuery object to work for it, in your case your load data functions do not return anything. But you can not return the jQuery object as it is the Anchorage Call. If the content returned by the server is HTML then you need to add a callback function to modify HTML because it is the only way to implement anything after AJAX calls.

Your code should look like this:

  $ (document) .ready (function () {function loadData (url, callback) {$ .post (url, function (Data) {callback ($ (data)); // Not sure that Jquery knows that the content is // html here, if so, then you get $ ()};} load data ('page01.php', function Html) can extract {var raw = html.filter ("# someId"). Html (); $ ("# content"). Html (raw);}); load data ('page02.fp', function ) {Var raw = html.filter ("# anotherId"). Html (); $ ("# content2"). Html (raw);});});    

No comments:

Post a Comment