开发者

Call jQuery function from Javascript function

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


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


Change:

jQuery().ajax({

to:

jQuery.ajax({

Reason: jQuery() refers to precisely nothing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜