I checked the server side, using directly browser GET or jquery.ajax GET to call and it could all return the correct page. That is to say, there is nothing wrong with the server side.
But when I try to use the following codes to do ajax call, I always get a 500 internal server error. The strange thing is I checked the console log and it seems that the parameters are not successfully transferred to the server. The ‘type’ and ‘source’ parameters when get to the server are all null.
The relevant codes are as below. The newXMLHttpRequest() is just a method to return correct object for different browser, which has been validated to be correct.
Anyone has any ideas about what goes wrong?
function updatePage(html){
var change =html;
var contents = document.getElementById("contents");
contents.innerHTML = change;
}
function submit(){
var t = document.getElementById("type").value;
var source = document.getElementById("src").value;
var req = newXMLHttpRequest();
req.onreadystatechange = getReadyStateHandler(req, updatePage);
req.open("GET", "RSSFetchServlet.do",true);
req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
req.send("type="+t+"&source="+source);
}
The actual problem is only when you are using POST can you use request.send method to send parameters. Otherwise, the req won’t encapsule the data into the URL.