Solved

jquery ajax .done to selector

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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 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 Loan Calculator Error 3 34
googleapis - jQuery.com and so forth 3 19
links not working 2 25
Question regarding to $.ajax() with type "POST" vs $.post() 4 28
DOM Attributes and Properties treatment with jQuery 1.6 by Ivo Stoykov jQuery (http://jquery.com/) 1.6 introduces .prop() (http://api.jquery.com/prop/) and .removeProp() (http://api.jquery.com/removeProp/) methods which allow modifying or removi…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…

763 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