+Функция 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

@ -534,7 +534,11 @@
try
{ $res = $stmt->execute();
} catch (Exception $e)
{ sendError(1,$e->getMessage()."\n".$sql_query);
{
if(str_contains($e->getMessage(), ']]')) //If already sending short error text.
sendError(1, $e->getMessage());
else
sendError(1, '[['.trt("SQL_query_error").']]'.$e->getMessage()."\n".$sql_query);
}
$result = $stmt->fetch(PDO::FETCH_NUM); //$obj_id
if($result[0]==''){ $result[0]=$obj_id; }
@ -569,7 +573,11 @@
try
{ $res = $db->query($sql_query);
}catch (Exception $e)
{ sendError(1,$e->getMessage());
{
if(str_contains($e->getMessage(), ']]')) //If already sending short error text.
sendError(1, $e->getMessage());
else
sendError(1, '[['.trt("SQL_query_error").']]'.$e->getMessage()."\n".$sql_query);
}
//записываем id удалённой записи для удаления без перезагрузки страницы через javascript
$xmlstring="";
@ -1290,9 +1298,7 @@ if ($code!=$_POST['code']) return new AuthError('invalid code');
$file='file_'.$num.'.xls';
$myFile = $dir.$file;
$fh = fopen($myFile, 'w');
if($fh)
{
if(($fh = @fopen($myFile, 'w')) !== FALSE){
fwrite($fh, '<html>'."\n");
fwrite($fh, ' <head>'."\n");
fwrite($fh, ' <title>'.$currNode->getAttribute("d").'</title>'."\n");
@ -1345,7 +1351,9 @@ if ($code!=$_POST['code']) return new AuthError('invalid code');
fwrite($fh, '</html>'."\n");
fclose($fh);
}
}else{
sendError(1,trt('Failed_to_generate_report'));
}
/*if($ext=="pdf")
{

View File

@ -1472,7 +1472,7 @@ class SRec
{
if(nodeCol.nodeName=="column")
{
if(nodeCol.getAttribute("n")==col){
if(nodeCol.getAttribute("n")==name){
break;
}
i++;

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)
{