The Internet provides the visitor with the visibility of each resource that is hosted on the network, and the browser with access through network protocols, mechanisms for invoking individual scripts, and transmitting / receiving information. The set of pages that make up the site has a common root - a unique link (domain name, unique node address).
It doesn't matter if the resource responds to the visit statically or dynamically creates a response. Even if the type and content of the page depend on any conditions, an indivisible unit of communication between the server and the client (browser) is a complete HTML document with code, pictures, style sheets, files and other necessary content and surroundings. If something is wrong here, the browser will display everything that it has “managed” to receive, disassemble and execute.
, . AJAX ( XMLHttpRequest) , .
,
- , IP- ( , -). , - "", : ? , ? - , .
, , , . , - , , . , - ( ) . ( ) , .
, , , ... , , , ... , , , ...
-
- - ( ), , . , , JavaScript, PHP . PHP- , AJAX : , .
. , -, , , , IP- . , , , .
, , : , , , IP- cookies. , , , . . AJAX-, , . () XMLHttpRequest .
- , , index , . , , , , . , : , .
- . , , , , - cookies .
: POST GET. . , .
, - , . , , . JavaScript-, AJAX- :
InitXML('../Mphp/scSrvPhpWord.php?cTask=GoPage' + '&cOwnerCode=' + cOwnerCode
+ '&cSessionCode=' + cSessionCode + '&cActiveItem=' + cActiveItem);
InitXML() ( var scXHR ):
function InitXML (scURL) {
scXHR = null;
if (window.XMLHttpRequest)
{ try
{ scXHR = new XMLHttpRequest();
} catch (e) {}
} else
if (window.ActiveXObject)
{ try
{ scXHR = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e)
{ try
{ scXHR = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {}
}
}
if (scXHR)
{
scXHR.open('GET', scURL);
scXHR.onreadystatechange = WaitReplySC;
scXHR.send(null);
};
}
URL . , , URL ( - scSrvPhpWord.php, ../Mphp/ root ), WaitReplySC(), XML- , .
PHP- - , , , , :
namespace PhpOffice\PhpWord;
ini_set('display_errors',1);
error_reporting(E_ALL ^E_NOTICE);
ignore_user_abort(true);
set_time_limit(12);
use PhpOffice\PhpWord\MphpObj\scDocuments;
require_once 'PhpOffice/PhpWord/Autoloader.php';
\PhpOffice\PhpWord\Autoloader::register();
, - 12 . PhpOffice\PhpWord *.docx.
AJAX- ('...cTask=GoPage' + '&cOwnerCode=' + cOwnerCode + '&cSessionCode=' + cSessionCode + '&cActiveItem=' + cActiveItem) - GET-, , :
$cTask = (isset($_GET['cTask']))? $_GET['cTask'] : '';
$cOwnerCode = (isset($_GET['cOwnerCode'])) ? $_GET['cOwnerCode'] : '';
$cSessionCode = (isset($_GET['cSessionCode'])) ? $_GET['cSessionCode'] : '';
$cActiveItem= (isset($_GET['cActiveItem'])) ? $_GET['cActiveItem'] : '';
:
switch ($cTask) {
case 'GoPage': // ( )
$cOwnerCode = 'cOwner';
$cSessionCode = 'cSession';
$cContents = 'cContents';
$cStatus = 'cStatus';
$cHtml = iconv ('UTF-8', 'CP1251', ' ');
$cActiveItem = iconv ('UTF-8', 'CP1251', ' ');
$cReply = "scSrvRM|GoPage|set|{$cOwnerCode}`{$cSessionCode}|{$cContents}`{$cStatus}|{$cHtml}|{$cActiveItem}";
break;
}
:
header("Content-Type: text/xml; accept-charset=utf-8");
header("Cache-Control: no-cache");
echo '<?xml version="1.0" encoding="UTF-8" ?>';
$cReply = iconv('CP1251', 'UTF-8', $cReply); // 'CP1251' 'UTF-8'
echo $cReply;
, , , , WaitReplySC:
function WaitReplySC() {
try {
if (scXHR.readyState == 4) {
if (scXHR.status == 200) { //
var TestReply = scXHR.responseText;
if ((TestReply.indexOf('Parse error') > 0) ||
(TestReply.indexOf('Notice') > 0)) alert(scXHR.responseText);
var cData = scXHR.responseText;
var aData = cData.split('|');
var cCmd = aData[1];
var cPos = aData[2];
var aOwnerSession = aData[3].split('`');
cOwnerCode = aOwnerSession[0];
var cSessionCode = aOwnerSession[1];
var aContentStatus = aData[4].split('`');
var cContent = aContentStatus[0];
var cStatus = aContentStatus[1];
var cHTML = aData[5]; // HTML-
var cVarValues = aData[6]; //
switch (cCmd) {
case 'GoPage':
var dTestLine = document.getElementById('scTestLine');
dTestLine.innerHTML = 'Reply = [' + cOwnerCode + ', '
+ cSessionCode + ', '
+ cContent + ', '
+ cStatus + ', '
+ cHTML + ', '
+ cVarValues + ']';
break;
}
} else {
document.getElementById('scAreaStatus').innerHTML = "Error!!!";
}
}
} catch(e) {}
}
, AJAX-, ( scTestLine):
Reply = [cOwner, cSession, cContents, cStatus, , ]
, jQuery WordPress
UTF-8, iconv() . .
WaitReplySC() , . InitXML ( scURL ) .
AJAX- «» .
() -, , . , jQuery AJAX jQuery.ajax() : jQuery.get() jQuery.post(). url settings ( +). jQuery.ajax() XMLHttpRequest-.
jQuery -: XHR.done() - . XHR.fail() - .
jqXHR.done() AJAX-. jqXHR.success().
Wordpress AJAX-. , . .
AJAX , , jQuery. , , .
AJAX - -. , . , , , .
. AJAX .
AJAX-, / , .
AJAX ( ):
<form name='fWelcome' action='index.php' method='post'>
<div id='scWelcomeLabel' style='left: 0px; top: 12px;'>:</div>
<div id='scWelcomeLabel' style='left: 0px; top: 35px;'>:</div>
<input type='text' name='cName' value='' id='scWelcomeField' title='' style='left: 56px; top: 8px;'>
<input type='text' name='cPass' value='' id='scWelcomeField' title='' style='left: 56px; top: 31px;'>
</form>
<div id='scWinClose' onclick='JavaScript: scfWelcomeCancel();' title=' '></div>
<div id='scWelcomeGo' onclick='JavaScript: scfWelcomeGo();'></div>
:
function scfWelcomeGo() {
var cName = document.fWelcome.cName.value;
var cPass = document.fWelcome.cPass.value;
InitXML('../Mphp/scSrvPhpWord.php?cTask=CheckWelcome'
+ '&cName=' + cName
+ '&cPass=' + cPass);
}
. , ( ) , , .