0

I have an ajax loaded content where i want to use a php script. The problem is that the script doesn't work and if i try to .load it inside the ajax loaded content it gives an error stating "$ is not defined".

Is there a way to load a php script inside a dinamically loaded content?

Thanks

edit: i solved the $ is not defiend thing. ok, some clarifiations. These are the steps: INDEX->menu click->ajax loads html into a div inside INDEX->inside that html i put a .load that should load the output of a php script. Unfortunately it doesn't work.

edit2: i was just stupid, the php script did load just well, the problem was i missed a character in the password for the db and it didn't load the content. Thanks

2
  • 1
    $ is not defined . Share your information.Probablity Jquery is not properly included Commented Sep 7, 2012 at 9:05
  • 1
    seems you haven't included jQuery library or i is not loaded, but that would be nice to see some code Commented Sep 7, 2012 at 9:09

4 Answers 4

2

"$ is not defined"

means the jquery library is not loaded check that

you have provided the correct path to the jQuery.js file, also include the jquery before including any other js library

try using a cdn hosted version of jquery

EDIT

when you bind events to the dynamically loaded elements you have to use .on(jquery 1.7+) or .delegate like

$(document).delegate( "yourElement", "load",
    function(e) {
        alert("loaded");
});
Sign up to request clarification or add additional context in comments.

2 Comments

i put the jquery lib loading script on top of the main page(where all the ajax code is laoded) and now it doesn't show that error anymore but still if i try to .load inside the loaded content it doesn't work.
edited the question, the problem was the human not the machine :)
1

No, you cannot load a PHP script and run it in the browser. If you setup your server to run the PHP script, you can load the output of the PHP script in your browser using AJAX.

Comments

0

Check whether the jquery package is included before your script and that should not redefined any where before your script like jquery.noConflict().

Comments

0

Check jquery library is loaded properly or not? as well as check your jquery must not conflict with other jquery so use jQuery.noConflcit(); to avoid error.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.