Jump to content

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.