Jump to content

Returning a value / object from jQuery plugin


viviosoft

Recommended Posts

Hello -

 

I have the following plugin.  It's working but I can't figure out how to return an object from the ajax method below.

 

Here's the function that calls the plugin:

 


        $('#list_results tr').live('click', function() {

            var itemRow = $(this).closest('#list_results tr');

               // Use plugin selectItem and pass options 

                $().selectItem({
                    dataFile: 'post-data/inv-get-item.php',
                    iValue: itemRow[0].id
                });

            alert(itemDataObj[0].id);  // trying to return obj from ajax on success of post??

            //  $('#vId').val(itemData[0].id);
            //  $('#itemCode').val(itemData[0].itemCode);
            //  $('#itemDesc').val(itemData[0].itemDesc);
            //  $('#itemWholesale').val(itemData[0].itemWholesale);
       
        });

 

Here's the plugin:  I want to return itemDataObj object to use within the above function.  I'm sure this can be done just not sure how. 

 

Any help would be great!  Thanks

 


(function($) {

    $.fn.selectItem = function(options){

        var defaults = {
            dataFile: null,
            iValue: null,
            resultsSelector: null
        },

        settings = $.extend({}, defaults, options);

        $.ajax({
          type: "POST",
          url: settings.dataFile,
          data: ({ itemID : settings.iValue }),
          dataType: "json",
          success: function(itemDataObj) {

              return itemDataObj[0];

          }
        })

    }

}) (jQuery);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.