documentation the data type of extraParams has to be an object, or a
function (that probably returns an object).
function getCategoryID() {
return {catID:categoryID};
// 'catID' will be the name of the categoryID in your script
// e.g. /?catID=vegetable
}
//Item Search for food name
$("#add-item #ITEMNAME").autocomplete("<?= site_url('aloha/
item_search'); ?>", {
extraParams: getCategoryID,
selectFirst: false,
formatItem: formatItem,
formatResult: formatResult
}).result(function(row, item, data) {
$('#add-item #ITEMNAME').val(item[0]);
$('#add-item #ITEMID').val(item[1]);
});
On Aug 27, 10:26 am, WhoButSB <whobu...@gmail.com> wrote:
> Thank you James for the help! I didn't know that the address is
> static once you've initialized it. I'm trying to work with the
> extraParams option but it doesn't seem to do anything. Here is how I
> have it set:
>
> //Item Search for food name
> $("#add-item #ITEMNAME").autocomplete("<?= site_url('aloha/
> item_search'); ?>", {
> extraParams: categoryID,
> selectFirst: false,
> formatItem: formatItem,
> formatResult: formatResult
> }).result(function(row, item, data) {
> $('#add-item #ITEMNAME').val(item[0]);
> $('#add-item #ITEMID').val(item[1]);
> });
>
> Just setting it like that doesn't seem to add anything to AJAX call.
>
> On Aug 27, 4:11 pm, James <james.gp....@gmail.com> wrote:
>
> > It's not really a variable scope problem. You're misunderstanding when
> > variables are set.
> > This is what's happening:
>
> > set global variable categoryID
> > add change event
> > add autocomplete with URL set to aloha/item_search/"+categoryID
> > -> categoryID is blank
> > do rest of page
>
> > When you do your change event, you do update the categoryID variable,
> > but not the autocomplete URL. Once that URL is set on initialization,
> > it's set. Changing categoryID is not going to change the autocomplete
> > URL.
>
> > I'm not sure if there is a way to update the autocomplete URL once
> > it's initialized without having to re-initialize it again. Is it
> > necessary that the URL has to change? Could you not use autocomplete's
> > 'extraParams' option to add additional data to the call?http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_datao...
> > The difference with using extraParams is that the values are
> > calculated at the time of the call, so you'll have dynamic values.
>
> > On Aug 27, 7:06 am, WhoButSB <whobu...@gmail.com> wrote:
>
> > > Hello All,
>
> > > I'm running into some issues where I'm alittle confused about the
> > > scope of my variables.
>
> > > I have this code:
>
> > > $(function(){
>
> > > var categoryID;
>
> > > //Aloha Item Category Dropdown Selection
> > > //Takes the Selected Value and adds it to Item Search Ending
> > > $("#add-item select[name='CategoryId']").change(function(){
> > > categoryID = $("#add-item select[name='CategoryId'] :selected").val
> > > ();
> > > return categoryID;
> > > });
>
> > > //Item Search for food name
> > > $("#add-item #ITEMNAME").autocomplete("<?= site_url('aloha/
> > > item_search'); ?>/"+categoryID, {
> > > selectFirst: false,
> > > formatItem: formatItem,
> > > formatResult: formatResult
> > > }).result(function(row, item, data) {
> > > $('#add-item #ITEMNAME').val(item[0]);
> > > $('#add-item #ITEMID').val(item[1]);
> > > });
>
> > > }
>
> > > What I'm trying to do is take a selection value from a drop down menu
> > > and append the value to the end of the URL in the auocomplete plugin.
> > > For some reason I'am not able to get this to work. Whenever I view
> > > the AJAX request it says that the value is undefined. But if I put a
> > > console.log() into where I select the value it comes up correctly. I
> > > believe its the way i'm defining the vairables scope. THank you for
> > > the help!
>
>
No comments:
Post a Comment