首页 > 解决方案 > 如何将 PHP 转换为 jQuery

问题描述

帮我把它转换成 jQuery。它工作正常,但我想将其转换为 jQuery。我尝试了几种方法,但没有成功:(这是我的代码...................... ..................................................... ..................................................... …………………………………………………………………………

<?php
$f_pId = $_GET['f_pId'];
$f_pName = $_GET['f_pName'];
$f_pStock = $_GET['f_pStock'];
$f_pPrice = $_GET['f_pPrice'];

echo "$f_pId, $f_pName, $f_pStock, $f_pPrice";

$xml = new DomDocument('1.0','UTF-8');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = true;
$xml->Load('products.xml');

$allProducts = $xml->getElementsByTagName('product');
$exist= 0;

foreach ($allProducts as $eachtProduct) {
$pId = $eachProduct->getElementsByTagName('pId');
if($f_pId == $pId->item(0)->nodeValue){
    $exist= 1;
    break;
}
}

if($exist== 1){
echo "<br />Product Already exists.";
header("refresh:3,url=simpleDomWithPhp3L.php");
}else{

$nProduct = $xml->createElement('product');

$npId = $xml->createElement('pId',$f_pId);
$npName = $xml->createElement('pName',$f_pName);
$npStock = $xml->createElement('pStock',$f_pStock);
$npPrice = $xml->createElement('pPrice',$f_pPrice);

$nProduct->appendChild($npId);
$nProduct->appendChild($npName);
$nProduct->appendChild($npStock);
$nProduct->appendChild($npPrice);

$productList = $xml->getElementsByTagName('productList');

$productList->item(0)->appendChild($nProduct);

if($xml->save('products.xml')){
    echo "<br />Product Added.";
    header("refresh:3,url=simpleDomWithPhp3L.php");
}else{
    echo "<br />errer";
    header("refresh:3,url=simpleDomWithPhp3L.php");
}
}
?>

标签: jqueryxmldom

解决方案


推荐阅读