Hello friends, hope this is the right site to post this, anyway let me tell you what's my problem.

I'm building a site that uses php, javascript where necessary and AJAX, my problem is that i need to set a cookie (the cookie works perfectly), but i need it to be created when the user clicks over a link image that displays a panel, so in my cookie.php file i have a function called readCookie():

function readCookie() {
		//Insert code here
		if (($_COOKIE['CCEM']) == true){
		echo '<script type="text/javascript">deshabilitaVoto();</script>'; 
		echo '<script type="text/javascript">alert("Disabled Panels");</script>';// ERASE

If the cookie (CCEM=name of the cookie) exists, then the panels will be disabled from the start until the cookie expires or is deleted. The deshabilitaVoto() function is called from a script called deactivatePanels.js

<script src="js/deactivatePanels.js" type="text/javascript"></script>

And in my function i have this code (AJAX + HTML):

function deshabilitaVoto() {
		// Call function createCookie() from cookie.php file.
		var myurl = "./bin/class/cookie.php";
				url: myurl,
				global: false,
				type: "POST",
				data: {action: 'createCookie'},
				async: false,
				success: function(data) {
				//Show if the cookie has been created.
				alert("The cookie has been created");
	/*i*/ console.info("Disable child panel.");
	$("li#panel1").html('').css({'background-image' : 'url("img/ejemploStatus.jpg")', 'background-repeat' : 'no-repeat', 'background-position' : '0 -291px', 'background-attachment' : 'scroll', 'background-color' : 'transparent'});
	$("li#panel2").html('').css({'background-image' : 'url("img/ejemploStatus.jpg")', 'background-repeat' : 'no-repeat', 'background-position' : '0 -291px', 'background-attachment' : 'scroll', 'background-color' : 'transparent'});
	$("li#panel3").html('').css({'background-image' : 'url("img/ejemploStatus.jpg")', 'background-repeat' : 'no-repeat', 'background-position' : '0 -291px', 'background-attachment' : 'scroll', 'background-color' : 'transparent'});
	$("li#panel4").html('').css({'background-image' : 'url("img/ejemploStatus.jpg")', 'background-repeat' : 'no-repeat', 'background-position' : '0 -291px', 'background-attachment' : 'scroll', 'background-color' : 'transparent'});

The only part that works is the HTML code, the panels change its image and the <a =href...>is deactivated but my AJAX code is not working, back to my previous file cookie.php i have this code that "suppousedly" should set the cokkie:

if (isset($_POST['action']) && !empty($_POST['action'])) {
		$action = $_POST['action'];
		switch($action) {
		case 'createCookie' : createCookie();break;

And of course i have a function in my php file called createCookie() that works perfectly if i set it when the page loads it

Anything you can do would be great and thanks for thinking about it, that's all i've got, if you need anything else i'll provide it.

$.ajax , $("li#panel1") what is this jQuery (write less, think less) ? Did you check it with a JavaScript debugger or a with firebug ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.