Improve company productivity with a Business Account.Sign Up

x
?
Solved

Jquery calling function after Ajax call

Posted on 2011-09-03
5
Medium Priority
?
1,875 Views
Last Modified: 2012-06-21
Hi,
I am trying to load available tags for the Jquery tagit plugin via Ajax call to my controller. It loads the Jason array as I can see in Firebug but throws this error:
$("#mytags").tagit is not a function

Any help is appreciated. The tagit plugin is installed and other than not using the Array it works just fine in the page.
This for example works just fine:
 $("#mytags").tagit({

        onTagRemoved: function (event, tag) {
            var mytag = $(tag).text();
            mytag = mytag.slice(0, -1);
            $.post("/Tags/RemoveTag?id=@Model.id" + "&" + "tag=" + mytag);
        }
    });

 
$.ajax({

        url: '/tags/AjaxGetTags',
        dataType: 'json',
        success: function (data) {
           $("#mytags").tagit({
                availableTags: data.tags
            });
        }
    });

Open in new window

0
Comment
Question by:nikomanek
  • 4
5 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 36479490
>> is not a function
that commonly occurs when the plugin is not "imported".  Are you sure you have the file to the path correct?  To verify this, using Firefox install the Web Developer toolbar. Once install click on Information > View Javascript.  If it is unable to import any of the javascript files, you will notice actual HTML code (as opposed to "pure" javascript code) with <title>404 - Page Not Found</title> or something very similar to it.
0
 

Author Comment

by:nikomanek
ID: 36479609
Hi Hielo,

I am using the tagit plugin in the page and it works without any problems. Just this one particular function does not. I can call $('#mytags').tagit(do something) without any problems but it stops working the moment I include it in a function as described. I just saw that jquery was loaded twice as Telerik loaded it as well. I disabled it for Telerik and now it accepts .tagit (yeah!) but throws a new error. The moment I start typing anything into the tag bar Jquery throws:
a is undefined
 (function(a,b){function cg(a){return d...a:a+"px")}}),a.jQuery=a.$=d})(window);
0
 

Author Comment

by:nikomanek
ID: 36479611
If using Visual Studio debugger I get:

Microsoft JScript runtime error: Unable to get value of the property 'length': object is null or undefined

In Jquery.min.js (version 1.5.1)
0
 

Accepted Solution

by:
nikomanek earned 0 total points
ID: 36479644
After preventing Telerik from loading Jquery a second time it worked.

@Html.Telerik().ScriptRegistrar().jQuery(false)
0
 

Author Closing Comment

by:nikomanek
ID: 36501305
I found the solution for this kind of behaviour in a Telerik forum.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

589 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question