I am using jquery ui dialog. In that dialog box, a php file(ex:test.php) is getting loaded using ajax call. Inside the test.php file, it contains some javascript code.
The problem is, after loading the test.php file in to jquery ui dialog, the javascript code inside the test.php file are not getting loaded. Any idea to solve this.
Thanks in advance.
If it is pure inline JavaScript, it should be executed. Does it implement $(document).ready()? In that case the JavaScript will not be executed because the event will never fire. Also be sure your JavaScript code comes after all HTML to allow your script to find the HTML elements.
Related
I have an issue loading a form in a bootstrap modal. I am using a service called Formstack to embed a form into my website. The embed code provided to me uses an external script to load the proper CSS, HTML, and JS into my page. The problem is that I am getting 10K+ warnings in my browser console once the page is loaded. All the warnings are the same. Each warning reads:
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
Here is a link to that javascript file: https://trustdale.formstack.com/forms/js.php/business_contact
Looking at the external javascript, EVERY line begins with document.write. I dont know if it matters, but I am loading the form in a bootstrap modal. Also note that the form loads totally fine... unless I'm missing something. How would I load my form without all the warnings?
I figured it out... I dont quite understand it yet, but I stumbled upon this https://github.com/krux/postscribe, which seems to make my code work. I created an empty div in my modal with an id of #formCode, then placed this section of code in my footer:
<script>
$( function(){
postscribe('#formCode', '<script src={!! $contact_form !!}><\/script>');
});
</script>
$contact_form only contains the value of my script "src" attribute.
Again, dont know how it works, just does. Maybe someone could elaborate
I have searched all over. They are saying the correct syntax to load jquery in normal mode is JHtml::_('jquery.framework', false);
I have tried and failed. I need to load jQuery so it works on all pages, so where should i put this inside the template index.php file? in head? above the head? does it need to be wrapped inside or not? I just need this to be spoon-fed to me because most forums assume people would already know where to put it...thanks.
You have 2 options. You can either call it normally which is exactly the same as the code you provided above, or you can all it in noConflict mode which is simply like this:
JHtml::_('jquery.framework');
This code should be place in the template's index.php file and can be placed anywhere as it will automatically be appended to the <head> tags of your template. As this is PHP code, it of course needs to go inside <?php ?> tags.
I am attempting to utilize apprise link on my website. I have a webpage on which I include the apprise javascript and css files. I also include my own javascript file containing the following function
function cant_find(data)
{
Apprise('Modal test');
}
I am utilizing jquery $.load() to load another page into a division on the page.
This works perfectly.
Within the callback of the load, I call my function
$('#div').load(base_url+'link',{},function(data){
cant_find();
});
This however does not work and gives the error:
$Apprise is null
Does anyone have any suggestions as to why?
Thanks
I have the following line of code:
$('#text').append('<h2 style="color:white">afdghadfg</h2>');
If I paste this code inside of a script tag in the html, it works fine. However, when placed inside a .js file it does nothing.
Know that the .js file has plenty of other working javascript and jQuery code, it is only this line that won't work.
Try this in your JS file:-
$(document).ready(function(){
$('#text').append('<h2 style="color:white">afdghadfg</h2>');
});
Could be the context you are putting it. Make sure it's not wrapped in a function and directly executable. Also check the JavaScript console (Firebug / CDT) to see if there are any errors.
Another thing to check is if it's getting executed before DOM ready, but I can't really tell you without seeing more code.
Interesting problem here from some inherited code I recently looked at. I'm trying to add a compression module to a project. It is loading all the JS and CSS files, combining them, minifying them, and compressing them. I've tried a number of solutions, but all of them have one fatal problem.
I have some javascript that is being loaded via Page.ClientScript.RegisterClientScriptBlock in the PreRender of the MasterPage. The compression module is loading as a Script Tag link in the MasterPage, but when I run the page... the code from the PreRender is lopped on top and is giving me a '$ is undefined' error, telling me jQuery isn't loaded yet.
Furthermore, I can't seem to get past the same problem when it comes to inline javascript on content pages.
Any ideas as to what is causing this? Enlighten me as I have no clue.
If have done this before with RegisterStartupScript (instead of RegisterClientScriptBlock) and called the $(document).ready(function() from WITHIN that script.
If the script tag link that eventually expands out to jquery is not in the head, but in the body of the page, then $ will be undefined when the script block executes, unless it is included in the html before the opening <form /> tag in the rendered html, which I understand is where RegisterClientScriptBlock spits out its script (just after that opening tag).
If this is not the case, and the joined/minified script is in the head, then I'd use a browser debugger such as Firebug or IE Dev Tools to verify that the jquery script is being correctly included in your combined script.
I know this answer is late to the party, but try calling ClientScript.RegisterClientScriptBlock in your OnPreRenderComplete (rather than OnPreRender) handler. This inserts the code later in the page rendering process.
All your jQuery code should be written inside the DOM-ready function:
$(function() {
// your code here
});
indipendently from where you place it in the page, 'cause the jQuery() function isn't avalaible before.