如何在不使用ajax刷新页面的情况下更新和显示购物车的内容? [英] how to update and show contents of shopping cart without refreshing the page using ajax?
本文介绍了如何在不使用ajax刷新页面的情况下更新和显示购物车的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
i在我的网页上有一个div我正在显示购物车(我正在使用php)。
但问题是每当我添加项目时购物车我必须刷新整个页面以获取购物车中显示的项目。
我甚至尝试过ajax但没有成功我获得了。
$下面的b $ b是链接点击事件的功能:
Hello,
i have a div in my webpage in which i am showing shopping cart(i am using php).
but the problem is whenever i add items in shopping cart i have to refresh the whole page to get the items shown in shopping cart.
I even tried with ajax but no success i gained.
below is the function on link's click event:
<function fun2(id)
{
var id=id;
$.ajax({
async: false,
url: 'header/sc1.php?action=add&code='+id, //the script to call to get data
//you can insert url argumnets here to pass to api.php for example "id=5&parent=6"
success: function(data) //on recieve of reply
{
}
});
}
我应该成功更新
should i update the
div
ajax的功能,但是如何?
请帮帮我..
in success function of ajax,but how?
please help me..
推荐答案
.ajax({
async: false ,
url:' header / sc1.php?action = add& code =' + id, // 脚本调用获取数据
// 您可以在此处插入url argumnets以传递给api。 php例如id = 5& parent = 6
成功:功能(数据) // 收到回复
{
}
});
}
.ajax({ async: false, url: 'header/sc1.php?action=add&code='+id, //the script to call to get data //you can insert url argumnets here to pass to api.php for example "id=5&parent=6" success: function(data) //on recieve of reply { } }); }
我应该成功更新
should i update the
div
ajax的功能,但是怎么样?
请帮帮我..
in success function of ajax,but how?
please help me..
如果你的返回数据是HTML,你可以用
If your returning data is HTML, you can use
('my-div-selector')。html(data) ...
如果是是一个应该放在特定元素中的数据,在div中,你应该以更手动的方式进行更新...
('my-div-selector').html(data)...
If it is a data that should be placed in specific elements INSIDE that div, you should do the update in a more manual fashion...
// data has two properties that hold amount of items in shopping cart and the total cost to pay
// and div has to sub-element to hold that data
success: function(data) {
这篇关于如何在不使用ajax刷新页面的情况下更新和显示购物车的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文