Solved

Jquery calling function after Ajax call

Posted on 2011-09-03
5
1,751 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now