0

I'm implementing some code that alerts users that my site is using cookies. If they consent I want to update my mysql database with the consent (eg 'yes' or 'no'). I got the current code from this site and it works great.

Currently it just prints the approval in the console(user approves) but I'm unsure how I should go about sending this data to php. I understand how to save to my database with php, it's just passing the data from jquery to php that I'm not sure how to go about. I do know a little ajax...

   <script type="text/javascript">
    $(document).bind("user_cookie_consent_changed", function(event, object) { 
      // true or false 
      console.log("User consent: " + $(object).attr('consent') ); 
    });
    </script> 

This prints out

1 Answer 1

1

I assume you are using core php. You need to create a function that will take data (coming from ajax) in form of YES or NO. Now Based on YES or NO you set condition in your function and update database. Now sending YES or NO from ajax.

var cookie = 'yes'; //User allows  
$.post('path to your function',{data:cookie},function(rdata){
   //anything returned from that function stored in rdata variable.
});

Now in your function you can get data by $_POST['data']

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.