dotkpay Posted April 8, 2012 Share Posted April 8, 2012 Hello, I have been trying to use a js function to call the jquery load utility. This helps me prevent multiple load items on the same page since the single load will be using variables passed on from html. So incase I have a page like the one below, how do I go about this... <html> <head> <script src="http://code.jquery.com/jquery-latest.min.js"></script> </head> <body> <button id="button">click</button> <div id="area"></div> <script type="text/javascript"> $(document).ready(function() { $('#button').click(function() { $('#area').load('example.html'); }); }); </script> </body> </html> Place your own file in the example.html spot Thanks in advance Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/ Share on other sites More sharing options...
AyKay47 Posted April 8, 2012 Share Posted April 8, 2012 the example you gave will load example.html into #area when #button is clicked. Are you trying to do something else? Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/#findComment-1335357 Share on other sites More sharing options...
dotkpay Posted April 8, 2012 Author Share Posted April 8, 2012 Yes, Am trying to send arguments to .load just like a normal js function works so that I can have many items calling the same .load instance Currently you would need a different .load function for every call. Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/#findComment-1335361 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 are you trying to load different pages or one page into many elements? Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/#findComment-1335503 Share on other sites More sharing options...
dotkpay Posted April 9, 2012 Author Share Posted April 9, 2012 Am trying to load different pages into one main index page. Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/#findComment-1335546 Share on other sites More sharing options...
AyKay47 Posted April 9, 2012 Share Posted April 9, 2012 The load method is the simplest way to grab data from the server, and it doesn't provide much flexibility. You can use the jquery AJAX API and return an object with the various data that you want to inject, and inject it where you want. Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/#findComment-1335631 Share on other sites More sharing options...
haku Posted April 9, 2012 Share Posted April 9, 2012 var something, something_else, another_thing, path; if(something == something_else) { path = "something.html"; } else if(something == another_thing) { path = "another_thing.html"; } else { path = "default.html"; } $('#area').load(path); Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/#findComment-1335690 Share on other sites More sharing options...
dotkpay Posted April 9, 2012 Author Share Posted April 9, 2012 Thanks to Haku and AyKay47 Link to comment https://forums.phpfreaks.com/topic/260554-using-jquery-load-inside-js-function/#findComment-1335842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.