Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript function returns variables as undefined
    text
    copied!<p>I am dynamically including a javascript file into a html page, which works fine. But when I run the function 'tryData' from the file the variables return as undefined. I've been looking for hours can't find a similar problem anywhere, does anyone know what the problem is?</p> <p>function in external file:</p> <pre><code>function tryData(id, size){ document.getElementById('content').innerHTML = '&lt;iframe src="http://domain.com/feeds/'+id+'/'+size+'/" id="frame"&gt;&lt;/iframe&gt;'; if(window.data){ clearInterval(timer); data(); } } </code></pre> <p>the line I am using to call it:</p> <pre><code>tryData(131, 'large'); </code></pre> <p>I know that the function is running because the frame is inserted as expected, but there's no content as the URL for the frame reads 'domain.com/feeds/undefined/undefined/', instead of 'domain.com/feeds/131/large/'.</p> <p>Thanks in advance for any help :)</p> <hr> <p>Here is an example of a html page with the function:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta name="robots" content="NOINDEX,NOFOLLOW" /&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;!-- Widget --&gt; &lt;div id="content"&gt;&lt;/div&gt; &lt;script&gt; (function(d, s) { var js = d.createElement(s), ins = d.getElementsByTagName(s)[0]; js.src = "http://domain.com/feeds/insert.js"; ins.parentNode.insertBefore(js, ins); tryData(131, 'large'); }(document, 'script')); &lt;/script&gt; &lt;!-- Widget End --&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>here is the js file:</p> <pre><code>function data(){ var u; u = document.URL; $.post("http://domain.com/data.php", { u: u} ); } function tryData(id, size){ document.getElementById('lsb').innerHTML = '&lt;iframe src="http://domain.com/feeds/'+id+'/'+size+'/" id="frame"&gt;&lt;/iframe&gt;'; if(window.data){ clearInterval(timer); data(); } } var script = document.createElement('script'); script.src = 'http://code.jquery.com/jquery-latest.js'; script.type = 'text/javascript'; document.getElementsByTagName('head')[0].appendChild(script); timer = setInterval(tryData, 100); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload