0

I am working on creating widget using PHP and Javascript. In a widget, you get a small code like this:

<div id="wd_id"></div><script type="text/javascript" src="http://localhost/hasanResearch/php/widgets/widget.js"></script><script type="text/javascript">init_widget()</script>

You need to paste this code in your html file. This piece of code calls a function init_widget() in widget.js. The script inside widget.js is somethis like this:

function init_widget(params){
    document.getElementById("wd_id").innerHTML='html code goes here';
}

This will load the entire html page. In my case, the JS file and all the files are located on server. I have copied the code in my local. When I open the html file in browser, it shows error as Uncaught ReferenceError: init_widget is not defined.

Do anyone have clue, why it is happening?

3
  • 1
    should http://localhost/hasanResearch/php/widgets/widet.js be http://localhost/hasanResearch/php/widgets/widget.js Commented Jun 3, 2013 at 6:33
  • sorry, my mistake. I have entered wrong filename is question. I have updated the question. Commented Jun 3, 2013 at 6:47
  • check in firebug whether this file is actually getting loaded. localhost/hasanResearch/php/widgets/widget.js Commented Jun 3, 2013 at 6:59

2 Answers 2

1
<script type="text/javascript" src="http://localhost/hasanResearch/php/widgets/widget.js"></script>

Instead of refering actual url src="http://localhost/hasanResearch/php/widgets/widget.js" Refere with your base url

Like src= "/hasanResearch/php/widgets/widget.js"

Sign up to request clarification or add additional context in comments.

Comments

1

your script tag is calling "widet.js" not "widget.js".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.