30/04/2013, 21:28
|
| | Fecha de Ingreso: octubre-2009
Mensajes: 21
Antigüedad: 15 años, 2 meses Puntos: 0 | |
Web response null Hola Comunidad,
Necesito una ayuda en mi codigo. He realizado debug y no doy con mi error solo encontre server response null;
aqui mi codigo:
Este file es: CartPHP.js
var xhr = createRequest();
function AddToCart()
{
var book=document.getElementById("book").innerHTML;
xhr.open("GET", "ManageCart.php?action=Add&book="+encodeURICompone nt(book)+"&value="+Number(new Date), true);
alert(book);
xhr.onreadystatechange=getData;
xhr.send(null);
}
function DeleteFromCart()
{
var book=document.getElementById("book").innerHTML;
xhr.open("GET", "ManageCart.php?action=Remove&book=" +
encodeURIComponent(book) +"&value="+Number(new Date), true);
xhr.onreadystatechange=getData;
xhr.send(null);
}
function getData()
{
if((xhr.readyState==4)&&(xhr.status==200)){
var serverResponse=xhr.responseXML;
var books=serverResponse.getElementByTagName("book");
alert("kkak"+books);
var cartDisplay=document.getElementById("cart");
cartDisplay.innerHTML="";
for(i=0; i<books.length;i++){
if(window.ActiveXObject){
cartDisplay.innerHTML+=""+books[i].firstChild.text;
cartDisplay.innerHTML+=""+books[i].firstChild.text+""+"<a href='#' onclick='DeleteFromCart'>Remove Item</a>";
}else{
cartDisplay.innerHTML+=""+books[i].firstChild.textContent;
cartDisplay.innerHTML+=""+books[i].lastChild.textContent+ ""+"<a href='#' onclick='DeleteFromCart'>Remove Item</a>";
}
}
}
}
Este file: ManageCart.php
<?php
session_register('Cart');
header('Content-Type: text/xml');
?>
<?php
$newitem = $_GET["book"];
$action = $_GET["action"];
if ($_SESSION["Cart"] != "")
{
$myCart = $_SESSION["Cart"];
if ($action == "Add")
{
if ($myCart[$newitem] != "")
{
$value = $myCart[$newitem] + 1;
$myCart[$newitem] = $value;
}
else
{
$myCart[$newitem] = "1";
}
}
else
{
$myCart= "";
}
}
else
{
$myCart[$newitem] = "1";
}
$_SESSION["Cart"] = $myCart;
ECHO (toXml($myCart));
function toXml($aCart)
{
$doc = new DomDocument('1.0');
$cart = $doc->createElement('cart');
$doc->appendChild($cart);
foreach ($aCart as $titleValue => $qtyValue)
{
$book = $doc->createElement('book');
$cart->appendChild($book);
$title = $doc->createElement('title');
$book->appendChild($title);
$value = $doc->createTextNode($titleValue);
$title->appendChild($value);
$quantity = $doc->createElement('quantity');
$book->appendChild($quantity);
$value2 = $doc->createTextNode($qtyValue);
$quantity->appendChild($value2);
}
$strXml = $doc->saveXML();
return $strXml;
}
?>
Este file: Catalogue1PHP.html
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><script type="text/javascript" src="xhr.js"></script>
<script type="text/javascript" src="CartPHP.js"></script></head>
<body>
<br/><img id="cover" src="begaspnet.jpg" /><br /><br />
<b>Book:</b><span id="book">Beginning ASP.NET with CSharp</span><br />
<b>Authors: </b><span id="authors"> Hart, Kauffman, Sussman, Ullman</span>
<br /><b>ISBN: </b><span id="ISBN">0764588508</span>
<br /><b>Price: </b><span id="price">$39.99</span>
<br /><br />
<a href="#" onclick="AddToCart()">Add To Shopping Card</a>
<a href="#" onclick="getData()">List</a>
<br /><br />
<span id="cart" ></span>
</body> </html>
Desde ya agradezco su tiempo y gentil ayuda!! |