+Функция postJsonData

This commit is contained in:
Igor I
2023-11-27 13:47:06 +06:00
parent 21335e4972
commit f49ab5fd52
3 changed files with 59 additions and 8 deletions

View File

@ -20,6 +20,18 @@ function trt(key)
else return val;
}
function deleteOption(sel,id){
if(typeof sel == 'string') sel=document.getElementById(sel);
let i=0;
while (i<sel.length) {
if(sel.options[i].value == id) {
sel.remove(i);
}else{
i++;
}
}
}
//Расширить плитку чтобы она занимала всю штртну области
//margin - С права и слева по одному пикселю (умножается на 2)
function resizeDivTile(parent,minWidth)
@ -168,7 +180,6 @@ function hideProgressBarIco()
}
}
//var eDiv=document.getElementById('eDiv'+this.uid);
function loadContent(url,obj)
{
if (typeof obj === 'string' || obj instanceof String)
@ -190,6 +201,37 @@ function loadContent(url,obj)
req.send( null );
}
//POST Json Data to server and Json in result
function postJsonData(url,data,fun){
if(typeof data !== 'string') {
data = JSON.stringify(data);
}
let req=createRequestObject();
req.onreadystatechange = function(req)
{
return function(){
if(req.readyState == 4 || typeof(req.readyState)=='undefined'){
if(req.status == 200) {
let json = null;
try {
json = JSON.parse(req.responseText);
} catch (e) {
}
if (json != null)
fun(true, json);
else
fun(false, req.responseText);
}else{
fun(false,trt('Failed_to_receive_data'));
}
}
};
}(req);
req.open( "POST", url, true );
req.setRequestHeader("Content-type", "application/json");
req.send(data);
}
//Вывести текст поверх окон с кнопочкой OK
function alert2(title,smallText,fullText,okFunc=null)
{
@ -773,6 +815,7 @@ function createRequestObject()
}
return new XMLHttpRequest();
}
//создать DOMParser
function CreateXMLDOC(xmlString)
{