?
Solved

jquery ajax .done to selector

Posted on 2014-02-28
2
Medium Priority
?
457 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 2000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
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…
Suggested Courses

830 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