Elxn
asked on
JQuery Pluggin Question
I have this plugin working just fine on this page: Tagit Working Here. Just start typing the word "book" in one of the fields and you'll see it works fine.
However, I'd like to see if I can put the ajax call inside a function and just call the function instead of having all that code on the page repeated. I have tried but it isn't working. I have no idea why, so I've turned to you experts for help!
Here is an example of the code that isn't working:
The HTML the jquery references is probably not the problem at all, but here it is:
The page its not working on is here: not working page.
Thanks for the help!
However, I'd like to see if I can put the ajax call inside a function and just call the function instead of having all that code on the page repeated. I have tried but it isn't working. I have no idea why, so I've turned to you experts for help!
Here is an example of the code that isn't working:
function get_tags(request,table){
$.ajaxSetup({ cache: false });
$.ajax({
url: "php/profile-tags.php",
dataType: "json",
data: {
txt: request.term,
t: table
},
success: function( data ) {
return data;
}
});
}
$(function() {
$('#tagit_1_bands').tagit({
tagSource:function( request, response ) {
var data = get_tags(request,'bands');
response( data );
},
triggerKeys:['enter', 'comma', 'tab'],
minLength:2,
maxTags:1,
select: true,
placeholder:'Your 1st favorite band...'
});
});
The HTML the jquery references is probably not the problem at all, but here it is:
<ul id="tagit_1_bands" class="tagit" data-name="bands1[]"></ul>
The page its not working on is here: not working page.
Thanks for the help!
ASKER
Yeah, I know the bands table won't return data. The only table with data in it is the books table. So everything needs to be done with the books table for now. But the problem is, on the page in my site where its not working, when i type stuff in a "books" field it still doesn't work for some reason.
Its returning something too, I put an alert() in the get_tags function and it shows me data, but it doesn't look like JSON when I alert it for some reason, just comma separated values are shown in the alert box. Perhaps this is the problem. I've tried converting the return data to JSON again (even though shouldn't it be JSON already?) but this doesn't seem to work either.
Go to this link and try typing "book" into the favorite books field. Just click on Top 10's and you'll see the field below.
Thanks.
Its returning something too, I put an alert() in the get_tags function and it shows me data, but it doesn't look like JSON when I alert it for some reason, just comma separated values are shown in the alert box. Perhaps this is the problem. I've tried converting the return data to JSON again (even though shouldn't it be JSON already?) but this doesn't seem to work either.
Go to this link and try typing "book" into the favorite books field. Just click on Top 10's and you'll see the field below.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yes great it is working fine on the books now.
However, one question remains. I need to pass get_tags the table name so it can work for all the different tables.
As you can see on this page (http://girlzunderground.com/profile.php) there are other tables besides the "books" table.
Thanks for your help!
However, one question remains. I need to pass get_tags the table name so it can work for all the different tables.
As you can see on this page (http://girlzunderground.com/profile.php) there are other tables besides the "books" table.
Thanks for your help!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The expert who commented on this question didn't answer my additional question. I had a need for the "get_tags" function to have a way to understand which table i needed to query to get the tags and he didn't show me how. So I went and figured it out myself and it is a working solution now. But, it was me who figured this extra thing out, so I have to say both solutions played a part in answering the question.
http://girlzunderground.co
Click it and you'll see it just returns the opening/closing array brackets but no actual data is in the array.
But if you switch the "t" paramater back to "books", you get a response with valid data as expected.
http://girlzunderground.co
Just sort out what is going on in the profile-tags.php script and you should be in good shape.
Hope that helps!