2

how can i call JQuery from plain Javascript ?

the file.js i have:

function setLanguageScript(lang) { 
messages = new Array();
if (typeof(lang) != 'undefined' && lang != null) {
    sessvars.lang = lang;
}
//setting default lang
if (typeof(sessvars.lang) == 'undefined' || sessvars.lang == null) {
    sessvars.lang = 'ro';
}

loadResources(sessvars.lang);
} 


function loadResources(language) {
jQuery().ajax({
type: "GET",
url: language + ".xml",
dataType: "xml",
success:function(xml) {
    alert("sucess");
        jQuery(xml).find('resource').each(
                function() {
                    var name = $(this).attr('name');
                    var content = (this).text();
                    alert(name + "-" + content);
                }
            );
        }
});
}

now in my html i have:

<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="js/i18n.js"></script>

and call to the JS function:

<a href="#" onclick="setLanguageScript('en');">EN</a>
<a href="#" onclick="setLanguageScript('ro');">RO</a>

FireBug gives the message: jQuery().ajax is not a function

1
  • .ajax() is a static method on the jQuery factory. Commented Jan 14, 2011 at 11:12

2 Answers 2

1

jQuery.ajax or just $.ajax instead of jQuery().ajax

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

2 Comments

ok, so i do the change and now the error i get:setLanguageScript is not defined
@Blitzkr1eg: Either you have an syntax error in your script or setLanguageScript is not in global scope. I suggest to put your code on jslint.com and see whether it contains any errors.
1

Change:

jQuery().ajax({

to:

jQuery.ajax({

Reason: jQuery() refers to precisely nothing.

1 Comment

ok, so i do the change and now the error i get:setLanguageScript is not defined

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.