I am attempting ajax call on change of a value in .jsp which is as follows:-
$(".custodianautocomplete").change(function() {
$('#custodianIDSelected').html($(this).val());
var IDSelected = $(this).val();
if (window.XMLHttpRequest) {
xRequest1 = new XMLHttpRequest();
} else {
xRequest1 = new ActiveXObject("Microsoft.XMLHTTP");
}
xRequest1.onreadystatechange = function() {
if ((xRequest1.readyState == 4) && (xRequest1.status == 200)) {
$(this).parent("td").next().find("input[name=hall_location]").val(xRequest1.responseText);
}
}
xRequest1.open("get", "/chbs/adm/getEmpName.jsp?q=" + IDSelected, "true");
xRequest1.send();
});
The execution of the webpage does not even reach getEmpName.jsp and an error as follows is shown in console
updateHallNames.jsp:254 GET http://localhost:8080/chbs/adm/getEmpName.jsp?q=ISRO008 500 (Internal Server Error)
(anonymous) # updateHallNames.jsp:254
dispatch # jquery-3.2.1.min.js:1627
q.handle # jquery-3.2.1.min.js:1589
The line No 254 shown in updateHallNames.jsp:254 is pointing at xRequest1.send();
I am unable to figure out the reason for the error.
I have resolved the error. The problem was with the error in the code of getEmpName.jsp. I found the details of the error by using standard ajax functionality with .fail(). The amended code is available at the link
here
Related
I'm having a surprisingly difficult time handling a simple 404 error response with XHR (AJAX)...
Basically, I have an "infinite scroll" page, where users scroll down the page and AJAX loads the next 50 results. At some point it will run out of results, and my PHP script is purposely set up to return a header 404 status when there are no more results. This is what I have:
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if(this.status == 200) {
console.log('display next results list');
}
else if(this.status == 404) {
console.log('end of list');
}
}
}
xhttp.open("GET", "index.php?page=101", true);
xhttp.send();
Problem: When a 404 is returned, I'm seeing the red "GET" 404 error in Chrome's dev console. When I click the error in console to see where it happens in the source, it specifically happens on this line xhttp.send(); The worst part about it is this seems to kill off XHR. So if I scroll back up again to see previous pages, XHR no longer works after it receives a 404. XHR just dies...
How do I fix this? How do I get XHR to see the 404 response and simply follow the else if(this.status == 404) { function without completely crashing???
Thanks
I am trying to sync both client-side and server-side scripts that the client intakes a value from the textbox and sends it to the server, upon which the server displays that input as a cookie.
Here is the code that I have so far
function loadCookie() {
//[1] make a new request object
var xhttp = new XMLHttpRequest();
//[2] set the request options
xhttp.open("GET", "index.html", true);
//[3] define what you will do when you ge a response (callback)
xhttp.onreadystatechange = function(){
if (this.readyState == 4 && this.status == 200) {
document.getElementById("input_response").innerHTML = this.responseText;
}
};
//[4] finally send out the request
xhttp.send();
}
I have the and the button but I am having issue of the page re-loading itself instead of taking the value of the input and showing it as a cookie in the server. I'm suspecting it is having to do with the URL by the index.html
I am using Google Drive javascript api V2 to download files. This has been working just fine for some time but today it is failing, returning status 0 with a blank response text. Looking at the network calls, I can see that I am authenticating successfully and navigating to the correct folders and retrieving a list of files but it will no longer download those files.
Looking deeper, I can see the initial response to each file download returns a status 307 (temporary redirect) and a redirect location in the response header. The browser automatically processes the location with a new request header but I do not get a response with any content, rather just an error with the status 0.
Is there a specific reason for the status 307 and is there a special way in which they should be handled?
This is the code used to download:
// Download file contents
downloadFile: function ( fileItem, callback ) {
var me = this,
accessToken,
xhr;
if ( fileItem.downloadUrl ) {
accessToken = gapi.auth.getToken().access_token;
xhr = new XMLHttpRequest();
xhr.onerror = function () {
callback( { error: { code: xhr.status, message: xhr.statusText } } );
};
xhr.open( 'GET', fileItem.downloadUrl, true );
xhr.setRequestHeader( 'Authorization', 'Bearer ' + accessToken );
xhr.overrideMimeType( "application/json" );
xhr.onreadystatechange = function () {
var DONE = this.DONE || 4;
if ( xhr.readyState === DONE ) {
if ( xhr.status === 200 ) {
callback( xhr.responseText );
} else {
callback( { error: { code: xhr.status, message: xhr.statusText } } );
};
};
};
xhr.send();
} else {
callback( { error: { code: "?", message: "Downloaded URL not specified" } } );
};
},
I am closing this question despite not getting a resolution. I have updated my code to use v3 of the Google Drive api and have got it working using that.
Strangely, if I used the HTTP request Url 'https://www.googleapis.com/drive/v3/files/<fileId>' it still didn't work but if I used the command:
gapi.client.drive.files.get( {
'fileId': fileItem.id,
'alt': 'media',
'mimeType': fileItem.mimeType
});
it works okay.
Not sure what Google have done as my previous code had been working for a couple of years without any change my end but at least I am back up and running again.
I am facing issue with form submit request sometimes and it getting aborted with 204 status code.
Please find the below code.
var f = document.forms[0];
try {
f.Guid.Value = "xx";
f.action = "Handler1.ashx";
f.submit();
} catch (e) {
SetError(e, null, "General");
}
return false;
Newbie to this - This code is works - in that the call to the script does what it is supposed to but returns the condition 500 and I can not see why. I am looking for any suggestions or changes that I should be making to make this work.
Thanks to all who respond.
function get_update_odometer(vehicle_key,odometer_value){
var url = "[%Catalyst.uri_for('/invoice/dispatch_util/get_update_odometer')%]";
new Ajax.Request(url, {
method: 'get',
parameters: {
key: vehicle_key,
ovalue: odometer_value
},
asynchronous:false,
onSuccess: successFunc,
onFailure: failureFunc
});
var return_v = $('rcontainer').innerHTML;
document.getElementById('odometer').value = return_v;
return true;
}
function successFunc(response){
if (200 == response.status){
var container = $('rcontainer');
var content = response.responseText;
container.update(content);
}
}
function failureFunc(response){
alert("Call has failed " + response.status );
}
Error code is coming from server side, and you provided the client part.
So have a look if your server script get_update_odometer is working, is callable by your web server and etc ...