viviosoft Posted June 5, 2011 Share Posted June 5, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/238500-returning-a-value-object-from-jquery-plugin/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.