jQuery eval of ajax inline script not throwing errors
Debugging Ajax code with Firebug
This question is quite similar, though old and without real answers.
I'm currently putting together an app that has scripts that get loaded in with an ajax request.
An example:
var main = _main.get();
main.load( someurl );
Where someurl is a page that contains an inline script element:
<script type="text/javascript">
$(document).ready( function(){
var activities = new activities();
activities.init();
});
</script>
jQuery will do a line by line eval of js that lives in inline script tags. The problem is, I get no errors or any information whatsoever in firebug when something goes awry.
Does anyone have a good solution for this? Or a better practice for loading pages which contain javascript functionality?
Edit: A little progress... so at the top of the page that is being loaded in via ajax, I have another script that was being included like this:
<script type="text/javascript" src="javascript/pages/activities.js"></script>
When I moved the inline $(document).ready() code in the page to the end of this included file, instead, syntax errors were now properly getting thrown.
As an aside, I threw a console.log() into the inline script tag, and it was being logged just fine. I also tried removing the $(document).ready() altogether, and also switching it out for a $(window)开发者_如何学JAVA.load() event. No difference. May have something to do with the inline scripts dependency on the included activities.js, I guess.
:: shakes head :: javascript can be a nightmare.
I suggest using http://api.jquery.com/jQuery.getScript/ for lazy loading Javascript or for getting html content http://api.jquery.com/load/
respectively:
$.getScript('path/to/file.js');
.. and
$('#content-wrap').load('path/to/html/file.html');
Both of theses methods are wraps around http://api.jquery.com/jQuery.ajax/ and have optional callback function parameters.
精彩评论