I am trying to make a running list with the ability to queue up multiple requests. I'm able to make single request and have the return be append to the correct DIV. But when I make two or more requests, before the first request is returned, the first GET is discarded by the webserver (project constraints...), and the second return is inserted into the first request's DIV.
EDIT: I'd like to ensure the related request gets appended into the correct DIV. If the GET request is terminated by the webserver, then I'll add a function on the error:{textStatus}
setting and append stock text into the div alerting the user of the error.
I'm using the jQuery plugin "Transform".
JS:
<script type="text/javascript">
$(function() {
var evtIncrmt = 0
$("#searchForm").submit(function (event) {
event.preventDefault();
evtIncrmt = evtIncrmt + 1
var $form = $(this),
//term = $form.find('input[name="cmdtextbox"]').val(),
url = $form.attr('action');
cmdInput = "<M ID=\"Input_MSGID\"><R ID=\"AscString_RECID\">OPD</R></M>"
$( "#listContainer" ).prepend( $(document.createElement( "div" ))
.attr({ id: evtIncrmt + "entry", title: "photo by a cohen" })
.text( "This is Event Number " + evtIncrmt )
);
$( "#" + evtIncrmt + "entry" ).append( $(document.createElement( "div" ))
.attr({ id: evtIncrmt + "entryXmlReturn", title: "review by w mitchell" })
.text( "Waiting for response. . " )
);
console.log("event increment before ajax call" + evtIncrmt);
$.ajax({
type: "GET",
timeout: 120000, /* 2mins */
context: "#" + evtIncrmt + "entryXmlReturn",
url: url,
data: {
XMLString: cmdInput ,
uqid: evtIncrmt
},
dataType: "text",
success: function (xmlReturn) {
console.log("event increment inside transform" + evtIncrmt);
$( "#" + evtIncrmt + "entryXmlReturn" ).transform({
xmlstr: xmlReturn,
xsl: { url: "xsl/StaticStyle.xsl" }
});
}
});
});
});
</script>
html:
<html>
<body>
<div class="links">
<form action="/" id="searchForm">
<input type="input" name="cmdtextbox" value="OPD" />
<input type="submit" value="Search" />
</form>
</div>
<div id="loadHTMLajax"></div>
<div id="listContainer">
<div id="2staticEntry">This is entry two.</div>
<div id="1staticEntry">Hello oldest entry number ONE</div>
</div>
</body>
</html>
Along with not working as intended, I'm sure I didn't use best practices while making this function. If you see areas where the code could be better written, please feel free to criticize.
This is my first question to the stackoverflow community, so hello, and thanks for all the anon usage I've gotten out of this resource over the years.