Solved

jquery ajax .done to selector

Posted on 2014-02-28
2
400 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
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now