I have an ajax function that behaves randomly. Sometimes a warning is displayed success finally. In other cases, the second warning is that
Failure: my status is 500.
promptIdpassed from the calling function. I checked prompturland promptId. A valid value from is promptIddisplayed in both cases (success and failure). The audio file that I am trying to play also plays in both cases (success and failure). I cannot understand the reason for this random behavior of the displayed alerts.
If 500 errorsuitable, it means that the resource was not found, but my application has access to the resource (which plays the audio file).
function ajax_playPrompt(promptId) {
alert(promptId)
var playPromptUrl = soapUrl + "?action=playPrompt&promptId=" + escape(promptId) + "&parentSessionId=" + parentSessionId;
alert(playPromptUrl);
playPrompt_http_request = getNewHttpRequest('text/plain');
playPrompt_http_request.onreadystatechange = callback_ajax_playPrompt;
playPrompt_http_request.open("GET", playPromptUrl, true);
playPrompt_http_request.send(null);
}
function callback_ajax_playPrompt() {
if (playPrompt_http_request.readyState != 4) {
alert("Returning bcause not 4");
return;
}
if (playPrompt_http_request.status == 200) {
alert("Success finally");
}
else {
alert("Failure:My status is "+playPrompt_http_request.status );
}
}
Also to support different browsers I use:
function getNewHttpRequest(contentType) {
var myRequest;
if (window.XMLHttpRequest) {
myRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
myRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
if (myRequest.overrideMimeType) {
myRequest.overrideMimeType(contentType);
}
return myRequest;
}
: . , ( ), .