javascript - How to implement the collection function without refreshing in php, it is best to have an example~
淡淡烟草味2017-07-05 10:02:03
0
5
4418
How to combine php with ajax to realize the collection function without refreshing, which is gray before clicking on an icon and red after clicking. It is best to have an example~Thank you guys~
Send an ajax request after clicking, and then set the icon color to red. At the same time, you need to pay attention to every time you request this page, remember to initialize the color of this collection icon.
Click to collect <script> //$id is the product id to be collected //url is the address of the operation data function collection($id){ if($id==''){return false; } var param={}; param.id=$id; $.post('url',param,function(data){ if(data==true){ alert('Collection successful'); }else{ alert('Please try again later'); } }) } </script> ///Data operation public function like(){ 1 post receiving data 2 Recent Row deposit operation 3 Return value (return true if successful, false if failed)
After the PHP processing is completed, it will be processed in the callback function.
You can go and see the detailed introduction of ajax method [ajax method]
Send an ajax request after clicking, and then set the icon color to red. At the same time, you need to pay attention to every time you request this page, remember to initialize the color of this collection icon.
Click to collect
<script>
//$id is the product id to be collected
//url is the address of the operation data
function collection($id){
if($id==''){return false; }
var param={};
param.id=$id;
$.post('url',param,function(data){
if(data==true){
alert('Collection successful');
}else{
alert('Please try again later');
}
})
}
</script>
///Data operation
public function like(){
1 post receiving data
2 Recent Row deposit operation
3 Return value (return true if successful, false if failed)
}
Use ajax without refreshing