1
0
forked from GitHub/gf-core

allow specifying content-type in ajax_http

This commit is contained in:
krangelov
2020-07-21 13:19:19 +02:00
parent 77a2630ed9
commit 2b09e70b4a

View File

@@ -89,7 +89,7 @@ function GetXmlHttpObject(handler)
return objXMLHttp return objXMLHttp
} }
function ajax_http(method,url,body,callback,errorcallback) { function ajax_http(method,url,body,contenttype,callback,errorcallback) {
var http=GetXmlHttpObject() var http=GetXmlHttpObject()
if (!http) { if (!http) {
var errortext="Browser does not support HTTP Request"; var errortext="Browser does not support HTTP Request";
@@ -109,17 +109,20 @@ function ajax_http(method,url,body,callback,errorcallback) {
} }
http.onreadystatechange=statechange; http.onreadystatechange=statechange;
http.open(method,url,true) http.open(method,url,true)
if (contenttype != null) {
http.setRequestHeader("Content-Type", contenttype)
}
http.send(body) http.send(body)
} }
return http return http
} }
function ajax_http_get(url,callback,errorcallback) { function ajax_http_get(url,callback,errorcallback) {
ajax_http("GET",url,null,callback,errorcallback) ajax_http("GET",url,null,null,callback,errorcallback)
} }
function ajax_http_post(url,formdata,callback,errorcallback) { function ajax_http_post(url,formdata,callback,errorcallback) {
ajax_http("POST",url,formdata,callback,errorcallback) ajax_http("POST",url,formdata,null,callback,errorcallback)
// See https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects // See https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects
} }