Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

JavaScript
<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
PHP
div
in success function of ajax,but how?

please help me..
Posted

1 solution

If your returning data is HTML, you can use $('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...
JavaScript
// 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) {
  $('selector-for-item-counter').val(data.items);
  $('selector-for-total-value').val(data.value);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900