Solved

jquery ajax .done to selector

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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript Form Change 5 31
Setting up JqueryUI with MVC 5 in Visual Studio 5 22
ajax wont trigger twice without a page refresh 7 14
AJAX Wordpress Not Reading Variable 2 27
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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 invoke it on a web page. 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.: (CODE)

789 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