2つのページがあります。1つのページは、古い方法のAJAXを使用して2番目のページにデータを要求するために実行するHTMLです。
ここで、データベースに新しいレコードを追加し、次のように返します。
var HttPRequest = false;
function doCallAjax(Mode, Page, ID) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxItemsGroupsRecord.php';
var pmeters = "titems_groups_GroupName=" + encodeURI(document.getElementById("items_groups_GroupName").value) +
"&titems_groups_sys_type_ID=" + encodeURI(document.getElementById("items_groups_sys_type_ID").value) +
'&myPage=' + Page +
"&tID=" + ID +
"&tMode=" + Mode;
HttPRequest.open('POST', url, true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function () {
if (HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Loading";
}
if (HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
エラーを挿入した場合、他のdivでマッサージエラーを返す必要があります。エラーメッセージを表示するだけで済みます。どうすればよいですか。
試しましたが、まだ動作しません
これは私のPHPコードです:
if($strMode == "ADD")
{
$sql_setting="SELECT * FROM stores_items";
$sr=mysql_query($sql_setting);
$S=@mysql_fetch_array($sr);
$stores_items_Name=$S["stores_items_Name"];
if($_POST["tstores_items_Name"]==$stores_items_Name){
echo $msg="<div class='gadget err_or'><div class='error_tit'>
<a rel='hide_err' class='hideerr' href='#'><img width='19' height='33' alt='picture' src='../images/spacer.gif'></a>
<a rel='close_err' class='closeerr' href='#'><img width='19' height='33' alt='picture' src='../images/spacer.gif'></a>
<h3>Message</h3>
</div>
<div class='error_msg'><p>its founded</p></div>
</div>";
}
elseif($_POST["tstores_items_Name"]=="" or $_POST["tstores_items_SalePrice_By_Store"]=="" or $_POST["tstores_items_BuyPrice_By_Store"]==""){
echo $msg="<div class='gadget err_or'><div class='error_tit'>
<a rel='hide_err' class='hideerr' href='#'><img width='19' height='33' alt='picture' src='../images/spacer.gif'></a>
<a rel='close_err' class='closeerr' href='#'><img width='19' height='33' alt='picture' src='../images/spacer.gif'></a>
<h3>Message</h3>
</div>
<div class='error_msg'><p>(*) Fill </p></div></div>";
}
else
{
$stores_items_AddDate=date('Y/m/d');
$strSQL = "INSERT INTO stores_items ";
$strSQL .="(stores_items_ID,stores_items_Name,stores_items_GroupId,stores_items_Barcode,stores_items_SalePrice_By_Store,stores_items_BuyPrice_By_Store,stores_items_Unit,stores_items_Currency,stores_items_Type,stores_items_AddType,stores_items_AddUser,stores_items_AddDate,stores_items_Delete,stores_items_StoreId,stores_items_sys_type_ID) ";
$strSQL .="VALUES ";
$strSQL .="('' , '".clean($_POST["tstores_items_Name"])."' , '".clean($_POST["tstores_items_GroupId"])."' , '".clean($_POST["tstores_items_Barcode"])."' , '".clean($_POST["tstores_items_SalePrice_By_Store"])."' ,'".clean($_POST["tstores_items_BuyPrice_By_Store"])."','".clean($_POST["tstores_items_Unit"])."','".clean($_POST["tstores_items_Currency"])."','".clean($_POST["tstores_items_Type"])."','1','$ausers_ID','$stores_items_AddDate' , '0','$ausers_StoreId','".clean($_POST["tstores_items_sys_type_ID"])."') ";
$objQuery = mysql_query($strSQL);
echo $msg="<div class='gadget err_bl'><div class='error_tit'>
<a rel='hide_err' class='hideerr' href='#'><img width='19' height='33' alt='picture' src='../images/spacer.gif'></a>
<a rel='close_err' class='closeerr' href='#'><img width='19' height='33' alt='picture' src='../images/spacer.gif'></a>
<h3>Message</h3>
</div>
<div class='error_msg'><p>Done</p></div></div>";
}
}