forked from GitHub/gf-core
minibar support.js: add function ajax_http_post for posting FormData
This commit is contained in:
@@ -63,27 +63,38 @@ function GetXmlHttpObject(handler)
|
|||||||
return objXMLHttp
|
return objXMLHttp
|
||||||
}
|
}
|
||||||
|
|
||||||
function ajax_http_get(url,callback,errorcallback) {
|
function ajax_http(method,url,body,callback,errorcallback) {
|
||||||
var http=GetXmlHttpObject()
|
var http=GetXmlHttpObject()
|
||||||
if (http==null) {
|
if (!http) {
|
||||||
alert ("Browser does not support HTTP Request")
|
var errortext="Browser does not support HTTP Request";
|
||||||
return
|
if(errorcallback) errorcallback(errortext,500)
|
||||||
}
|
else alert(errortext)
|
||||||
var statechange=function() {
|
}
|
||||||
if (http.readyState==4 || http.readyState=="complete") {
|
else {
|
||||||
if(http.status<300) callback(http.responseText,http.status);
|
var statechange=function() {
|
||||||
else if(errorcallback) errorcallback(http.responseText,http.status);
|
if (http.readyState==4 || http.readyState=="complete") {
|
||||||
else alert("Request for "+url+" failed: "
|
if(http.status<300) callback(http.responseText,http.status);
|
||||||
+http.status+" "+http.statusText);
|
else if(errorcallback) errorcallback(http.responseText,http.status);
|
||||||
}
|
else alert("Request for "+url+" failed: "
|
||||||
|
+http.status+" "+http.statusText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
http.onreadystatechange=statechange;
|
||||||
|
http.open(method,url,true)
|
||||||
|
http.send(body)
|
||||||
}
|
}
|
||||||
http.onreadystatechange=statechange;
|
|
||||||
http.open("GET",url,true)
|
|
||||||
http.send(null)
|
|
||||||
//dump("http get "+url+"\n")
|
|
||||||
return http
|
return http
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ajax_http_get(url,callback,errorcallback) {
|
||||||
|
ajax_http("GET",url,null,callback,errorcallback)
|
||||||
|
}
|
||||||
|
|
||||||
|
function ajax_http_post(url,formdata,callback,errorcallback) {
|
||||||
|
ajax_http("POST",url,formdata,callback,errorcallback)
|
||||||
|
// See https://developer.mozilla.org/En/XMLHttpRequest/Using_XMLHttpRequest#Using_FormData_objects
|
||||||
|
}
|
||||||
|
|
||||||
// JSON via AJAX
|
// JSON via AJAX
|
||||||
function ajax_http_get_json(url,cont) {
|
function ajax_http_get_json(url,cont) {
|
||||||
ajax_http_get(url,function(txt) { cont(eval("("+txt+")")); });
|
ajax_http_get(url,function(txt) { cont(eval("("+txt+")")); });
|
||||||
|
|||||||
Reference in New Issue
Block a user