jsfiddle - return html with jquery when


while trying to echo back some html on jsfiddle using jquery deferreds, I'm not getting any data back.

function showData(data1, data2) { console.log(data1[0]); console.log(data2); } function method1() { return $.ajax({ type: "post", url: "/echo/html/", data: JSON.stringify("test1"), dataType: 'html' }); } function method2() { return $.ajax({ type: "post", url: "/echo/html/", data: {data: "test2"}, dataType: 'html' }); } $.when(method1(), method2()).then(showData);

I can't understand what I've done wrong here. Passing the data as an object or as JSON.stringify, neither seems to work. <a href="http://jsfiddle.net/VAy5g/" rel="nofollow">http://jsfiddle.net/VAy5g/</a>


Try using an asynchronous method like deferred.pipe(). Some example is shown in stackoverflow thread 10253192 jquery - Understanding Deferred.pipe().

This is the jquery documentation relates to your problem, <a href="http://api.jquery.com/jQuery.when/" rel="nofollow">http://api.jquery.com/jQuery.when/</a>. Read it careful and see the jQuery.ajax() documentation for a complete description of success and error cases for an ajax request. Adapt the prototype of the when exactly and do noz seperate the function. Make sure that console.log is doing something at this place and alter it im a way your function does what you wish it to do and where it should do it. It might be better logging into text files.


A somewhat belated response to this question.

The problem is not your jQuery. That works fine. The only problem is your use of jsFiddle's /echo/html API. Compare your code:

data: {data: "test2"},

to <a href="http://jsfiddle.net/VAy5g/22/" rel="nofollow">working code</a>:

data: {html: "test2"},

The property that specifies the response is data.html, not data.data.

<a href="http://jsfiddle.net/VAy5g/22/" rel="nofollow">This version of your code</a> works as expected.


  • list/vector of class methods in a class variable
  • In PHP, are objects methods code duplicated or shared between instances?
  • predict function in RandomForest package gives different results from randomForest with xtest and yt
  • How do I convert Rtf to Text using ASP.Net?
  • How to get scenario name from a scenario outline in cucumber using java
  • Turn list output into an array of objects or something similar using Powershell
  • Using C# Attributes and documentation
  • Conditional render in tagfile depending on whether the attribute is specified or not
  • formediting modals shows at wrong position
  • Converting datatype Char to Nvarchar
  • How can I add web content type in liferay 6?
  • Reading XML into Datatable gives incorrect DateTime when the time has Time Zone info
  • How do I check if System::Collections:ArrayList is empty / nullptr / null?
  • Creating a C++ function that calls other Lua function
  • testing a POST using phpunit in laravel 4
  • What is corresponding c++ data type to SQL numeric(18,0) data type?
  • How to use function wrapper in mustache.php?
  • bad substitution shell- trying to use variable as name of array
  • pyodbc doesn't report sql server error
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Meteor: Do Something On Email Verification Confirmation
  • Using jQuery closest() method with class selector
  • Array.prototype.includes - not transformed with babel
  • Where to put my custom functions in Wordpress?
  • Statically linking a C++ library to a C# process using CLI or any other way
  • R: gsub and capture
  • RestKit - RKRequestDelegate does not exist
  • AT Commands to Send SMS not working in Windows 8.1
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • bootstrap to use multiple ng-app
  • Comma separated Values
  • How to get icons for entities from eclipse?
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • WPF Applying a trigger on binding failure
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • How do I configure my settings file to work with unit tests?
  • Turn off referential integrity in Derby? is it possible?
  • Is it possible to post an object from jquery to bottle.py?
  • JaxB to read class hierarchy
  • How to load view controller without button in storyboard?