Solved

jquery ajax .done to selector

Posted on 2014-02-28
2
411 Views
Last Modified: 2014-03-01
Why does returnedval += "hello" + data not end up in the input box?
options.cmd does end up in the input box.
I thought by naming a variable returnedval and appending to it in the .done section that I would get the ajax data value.




function runPlugIn(el)
{
      $(el).closest('div').find('input[type=text]').runner({'cmd':'HREmpmstr'})
      
}


(function ( $ ) {
      
      
    $.fn.runner = function( options ) {
      var returnedval = options.cmd
 
      $.ajax({data:{'cmd':options.cmd},url: 'PLUGINW/runners/runner.asp'}).done(function(data) {returnedval += "hello" + data});
      
      
      return $(this).each(function(){$(this).val(returnedval)})
       

    };
 
}( jQuery ));
0
Comment
Question by:KeithMcElroy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:KeithMcElroy
ID: 39896303
adding async: false makes it work, however, is that a good practice?
0
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
ID: 39896337
async:false is bad, as you won't be able do anything else on the page til the script finishes

.done has nothing to do with waiting for the ajax call to be returned.

	  $.ajax({data:{'cmd':options.cmd},context:this,url: 'PLUGINW/runners/runner.asp',
		success:function(data) {
			returnedval += "hello" + data
			return returnedval
		}
	  });

Open in new window

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question