<!DOCTYPE html>
<html>
<head>
<script data-dojo-config="async: 1"
src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<script data-require="jquery@*" data-semver="3.1.1" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body>
<h1>Hello Plunker!</h1>
<h3>Console:</h3>
<div id="console"></div>
</body>
</html>
var LocationIdSet = [];
require(['dojo/Deferred', 'dojo/domReady!'], function(Deferred, dom) {
projectAreaSet = ['a', 'b', 'c'];
/*for (i = projectAreaSet.length - 1; i >= 0; i--) {
var saveProject = asyncProcess(projectAreaSet[i], i);
}*/
var i = projectAreaSet.length - 1;
var saveProject = asyncProcess(projectAreaSet[i], i);
//move this function out of the for statement, since it
//doesn't need to be defined for each iteration
//because of that, accept the iterator value (i.e. i)
function asyncProcess(geometry, i) {
console.log("asyncProcess");
var deferred = new Deferred(); //Dojo, not jQuery
$.ajax({
type: "GET", //"POST",
data: "",//JSON.stringify(locationProfile),
url: "api/LocationProfile/Create/" + i,
//contentType: "application/json", //because we are just returing plaintext files
})
.done(function(data) {//success not a function - perhaps you are using an earlier version of jquery?
//we can't set the content type header on the plain text files in this example
data = JSON.parse(data);
LocationIdSet.push(data.LocationId);
console.log("data.LocationId ", data.LocationId,' i: ',i);
if (i > 0) {
asyncProcess(projectAreaSet[i-1], i-1);
}
deferred.resolve();
});
return deferred.promise;
}
});
originalLog = console.log;
console.log = function() {
var string = Array.prototype.join.call(arguments,' ');
$('#console').html(function(index, oldHtml) {
return oldHtml +'<br />'+ string;
});
originalLog.apply(null,arguments);
}
/* Styles go here */
{
"LocationId": 7614
}
{
"LocationId": 7615
}
{
"LocationId": 7613
}