Solved

Jquery calling function after Ajax call

Posted on 2011-09-03
5
1,787 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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…
Suggested Courses

739 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