When I have an ajax call why should i set xmlhttpRequest.setRequestHeader ? is it not obvious from the ajax object t开发者_如何学编程hat we are sending an ajax request.
You have to understand first that AJAX request are HTTP request. When you add
xmlhttp.setRequestHeader('Content-Type','XXXXXXXXX');
it adds an header that define what kind of data will be contained in the body of the request. application/x-www-form-urlencoded
means that the data will be form data. The data format could be something else. It's just that form data is the most common thing you will send to a server.
精彩评论