getscript

Can I prevent history.popstate from triggering on initial page-load?

我只是一个虾纸丫 提交于 2019-11-27 06:30:37
I'm working on a site that serves content via AJAX. If you click an item in the menu, a content div gets updated with $.get response, nothing fancy. I'm implementing history.pushState to allow navigation with the browser's back/forward button. I have the following to load content on history navigation: $(function() { $(window).bind("popstate", function() { $.getScript(location.href); }); }); The problem is, when a page is loaded for the first time, this function does $.getScript so the page is loaded immediately again. The first time the page is loaded it renders the initial HTML view, then on

jQuery getScript returns an parse error exception

给你一囗甜甜゛ 提交于 2019-11-27 06:21:20
问题 I'm trying to load two scripts with the $.getScript function of getting Google Map script, then after that is loaded, I get another script (goMap) which makes map applets easily to be made. However, when loaded, the first script of getting Google Map API is good, then the second script returns a parse error and shows this: TypeError: 'undefined' is not a constructor' Yet, I don't know where that is referencing from or which line, I think it must be trying to execute the Geocoder on this file

jQuery.getScript alternative in native JavaScript

…衆ロ難τιáo~ 提交于 2019-11-27 00:53:52
I'm trying to load JS scripts dynamically, but using jQuery is not an option. I checked jQuery source to see how getScript was implemented so that I could use that approach to load scripts using native JS. However, getScript only calls jQuery.get() and I haven't been able to find where the get method is implemented. So my question is, What's a reliable way to implement my own getScript method using native JavaScript? Thanks! Mathletics You can fetch scripts like this: (function(document, tag) { var scriptTag = document.createElement(tag), // create a script tag firstScriptTag = document

Jquery getScript caching

不想你离开。 提交于 2019-11-26 18:09:06
问题 By Default $.getScript() disables caching and you can use $.ajaxSetup and set caching to true. When testing if the script is actually cached with Firebug most of the time the script is coming back at 200 (Which means the script is a fresh copy) and one in maybe 20 or 30 times it will come back 304 (meaning it used a cached version). Why is it getting a new copy the vast majority of the time? $.ajaxSetup({ cache: true }); $.getScript( scriptFile ); The files that getScript retrieves have not

How can I include all JavaScript files in a directory via JavaScript file?

风格不统一 提交于 2019-11-26 16:12:05
问题 I have a bunch of JavaScript files that I would like to include in the page, but I don't want to have to keep writing <script type="text/javascript" src="js/file.js"></script> So is there a way to include all files in a directory (unknown size)? Can I do something like... $.getScript("js/*.js"); ... to get all the JavaScript files in the "js" directory? How can I do this using jQuery? 回答1: In general, this is probably not a great idea, since your html file should only be loading JS files that

Can I prevent history.popstate from triggering on initial page-load?

余生颓废 提交于 2019-11-26 12:55:13
问题 I\'m working on a site that serves content via AJAX. If you click an item in the menu, a content div gets updated with $.get response, nothing fancy. I\'m implementing history.pushState to allow navigation with the browser\'s back/forward button. I have the following to load content on history navigation: $(function() { $(window).bind(\"popstate\", function() { $.getScript(location.href); }); }); The problem is, when a page is loaded for the first time, this function does $.getScript so the

jQuery.getScript alternative in native JavaScript

﹥>﹥吖頭↗ 提交于 2019-11-26 09:28:17
问题 I\'m trying to load JS scripts dynamically, but using jQuery is not an option. I checked jQuery source to see how getScript was implemented so that I could use that approach to load scripts using native JS. However, getScript only calls jQuery.get() and I haven\'t been able to find where the get method is implemented. So my question is, What\'s a reliable way to implement my own getScript method using native JavaScript? Thanks! 回答1: You can fetch scripts like this: (function(document, tag) {