AJAX第二次没有工作 [英] AJAX not working second time
本文介绍了AJAX第二次没有工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
此代码第一次完美运行,但第二次失败。我尝试过cache:false但是没有用。
我该怎么做?
谢谢,
Akkywadhwa
< pre lang =javascript> function onQuantityChange(id)
{
var quantity = $( # + id + 选项:选中)。text();
$ .ajax({
type: POST ,
dataType: json,
url: cart.php?id = + id + & quantity = +数量,
成功:功能(数据)
{
$(' 。success,.warning,.attention,.information,.error') .remove();
if (data.HTML!= null )
{
// 更新页面视图的代码
}
else
{
alert( 无法获取);
}
},
错误: function (){
alert( 事件错误:onselect);
}
});
}
for($ i = 0; $ i< count($ _ SESSION) [ contents]); $ i ++)
{
$ sql = 从ID =的产品中选择*。$ _ SESSION [ contents] [$ i] [ ItemCode跨度>];
$ con>查询($ sql);
while($ row = $ con> Row())
{
echo < tr>;
echo < td class = \\ \\ name\ >中跨度>;
echo < a href = \\ \\\>。$ row->名称。 。$ row-> Unit。 < / a>;
echo < / td> 跨度>;
echo < td class = \\ \\details \>< span class = \MRP \> Rs $ row-> MRP< / span>< / td>< td class = \details \ >< span class = \details \> Rs $ row-> SP< / span>;
echo < / td> 跨度>;
echo < / td> 跨度>;
echo < td class = \\ \\ quantity\ >中跨度>;
echo < select id = \\ \\$ row-> ID \onchange = \onQuantityChange('$ row-> ID')\>;
for($ j = 1; $ j< 21; $ j ++)
{
if($ j == $ _ SESSION [ contents] [$ i] [ 数量])
{
echo < option value = \$ j\selected> $ j< / option>;
}
其他
{
echo < option value = $ j> $ j< / option>;
}
}
echo < /选择> 中跨度>;
echo < / td> 跨度>;
echo < td id = \\ \\$ row-> ID \class = \total \>。$ _ SESSION [ contents] [$ i] [ quantity] * $ row-> SP。 < / td>;
echo < td class = \\ \\ remove\ >中跨度>;
echo < img src = \\ \\Stylesheets / image / remove.png \> ID')\title = \删除\/>;
echo < / td>;
echo < / tr>;
}
}
}
其他
{
echo 内容数组不存在。;
}
echo < / tbody>;
echo < / table> ;;
echo < / div>;
echo < div class = \\ \\ 购物车-totals\ >中跨度>;
echo < table class = \\ \\ right\ >中跨度>;
echo < tr>< /跨度>;
echo < td class = \\ \\total \width = \200px \align = \right \>;
echo < h3> Shipping< / H3>中跨度>;
echo < / td> 跨度>;
echo < td class = \\ \\total \width = \70px \align = \right \>;
echo 免费 ;
echo < / td> 跨度>;
echo < / tr> 跨度>;
echo < tr>< /跨度>;
echo < td class = \\ \\total \width = \200px \align = \right \>;
echo < h3> Total< / H3>中跨度>;
echo < / td> 跨度>;
echo < td class = \\ \\total \width = \70px \align = \right \>;
echo < h3 id = \\ \\FinalTotal \> Rs。$ _ SESSION [ total] 。 < / h3>;
echo < / td> 跨度>;
echo < td class = \\ \\total \width = \40px \>;
echo < / td> 跨度>;
echo < / tr> 跨度>;
echo < / table> 跨度>;
echo < / div> 跨度>;
echo < / div> 跨度>;
echo < div id = \BackForthButtons\>;
echo < div class = \\ \\ checkout\ >中跨度>;
echo < div class = \\ \\cart-modules left\>;
echo < / div>< ; / div>< div class = \right \>< a class = \button \href = \checkout.php \>;
echo < span class = \\ \\ proceed\ >结帐< /跨度>< / A>< / DIV GT&;跨度>;
echo < div class = \\ \\ right\ >中跨度>;
echo < a class = \\ \\button \href = \http://www.cartup.in \style = \background:#454545;保证金:2px 5px; \>;
echo < span class = \\ \\continue \>添加更多项目< / span>;
echo < / a> 跨度>;
echo < / div> 跨度>;
echo < / div> 跨度>;
echo < / div> 跨度>;
echo < / div> 跨度>;
echo < / div> 跨度>;
echo < / div> 跨度>;
echo < / div> 跨度>;
echo < / div> ;
解决方案
( # + id + option:selected)。text( );
.ajax({
type: POST ,
dataType: json,
url:< span class =code-string> cart.php?id = + id + & quantity = +数量,
成功:功能(数据)
{
(' 。success,.warning,.attention ,.信息,.e 。RROR'跨度>)除去();
if (data.HTML!= null )
{
// 更新页面视图的代码
}
else
{
alert( 无法得到它);
}
},
错误: function (){
alert( 事件错误:onselect);
}
});
}
for(
Hello,
This code works perfectly for the 1st time but fails for the second time. I have tried cache: false but it didn't work.
How can I do this?
Thanks,
Akkywadhwa
function onQuantityChange(id)
{
var quantity=$( "#"+id+" option:selected" ).text();
$.ajax({
type: "POST",
dataType: "json",
url: "cart.php?id="+id+"&quantity="+quantity,
success: function(data)
{
$('.success, .warning, .attention, .information, .error').remove();
if(data.HTML!=null)
{
//code to update the view on page
}
else
{
alert("Unable to get it");
}
},
error: function(){
alert("Error in event:onselect");
}
});
}
for($i=0;$i<count($_SESSION["contents"]);$i++)
{
$sql="select * from products where ID=".$_SESSION["contents"][$i]["ItemCode"];
$con->Query($sql);
while($row=$con->Row())
{
echo "<tr>";
echo "<td class=\"name\">";
echo "<a href=\"\">".$row->Name." ".$row->Unit."</a>";
echo "</td>";
echo "<td class=\"details\"><span class=\"MRP\">Rs $row->MRP</span></td><td class=\"details\"><span class=\"details\">Rs $row->SP</span>";
echo "</td>";
echo "</td>";
echo "<td class=\"quantity\">";
echo "<select id=\"$row->ID\" onchange=\"onQuantityChange('$row->ID')\" >";
for($j=1;$j<21;$j++)
{
if($j==$_SESSION["contents"][$i]["quantity"])
{
echo "<option value=\"$j\" selected>$j</option>";
}
else
{
echo "<option value=$j>$j</option>";
}
}
echo "</select>";
echo "</td>";
echo "<td id=\"$row->ID\" class=\"total\">".$_SESSION["contents"][$i]["quantity"]*$row->SP."</td>";
echo "<td class=\"remove\">";
echo "<img src=\"Stylesheets/image/remove.png\" >ID')\" title=\"Remove\"/>";
echo "</td>";
echo "</tr>";
}
}
}
else
{
echo "contents array doesnt exists.";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
echo "<div class=\"cart-totals\">";
echo "<table class=\"right\">";
echo "<tr>";
echo "<td class=\"total\" width=\"200px\" align=\"right\">";
echo "<h3>Shipping</h3>";
echo "</td>";
echo "<td class=\"total\" width=\"70px\" align=\"right\">";
echo "Free";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td class=\"total\" width=\"200px\" align=\"right\">";
echo "<h3>Total</h3>";
echo "</td>";
echo "<td class=\"total\" width=\"70px\" align=\"right\">";
echo "<h3 id=\"FinalTotal\">Rs ".$_SESSION["total"]."</h3>";
echo "</td>";
echo "<td class=\"total\" width=\"40px\">";
echo "</td>";
echo "</tr>";
echo "</table>";
echo "</div>";
echo "</div>";
echo "<div id=\"BackForthButtons\">";
echo "<div class=\"checkout\">";
echo "<div class=\"cart-modules left\">";
echo "</div></div><div class=\"right\"><a class=\"button\" href=\"checkout.php\">";
echo "<span class=\"proceed\">Checkout</span></a></div>";
echo "<div class=\"right\">";
echo "<a class=\"button\" href=\"http://www.cartup.in\" style=\"background: #454545; margin: 2px 5px;\">";
echo "<span class=\"continue\">Add more items</span>";
echo "</a>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
解决方案
( "#"+id+" option:selected" ).text();
.ajax({ type: "POST", dataType: "json", url: "cart.php?id="+id+"&quantity="+quantity, success: function(data) {
('.success, .warning, .attention, .information, .error').remove(); if(data.HTML!=null) { //code to update the view on page } else { alert("Unable to get it"); } }, error: function(){ alert("Error in event:onselect"); } }); }
for(
这篇关于AJAX第二次没有工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文