I am trying to give feedback to a user. If they have added something already they will get a message saying that This attraction has already been added to your itinerar. If a user doesnt have the attraction in their itinerary they will get a success message. Although it always says that the attraction has already been added, even if it hasn't. There are no errors, does anyone know why this keeps happening. Below is the code for the function.
function addAttractionItinerary(ev) {
var id=$(ev.target).parents('div.Attraction')[0].$data.attraction_id;
$.post('php/validation.php', {"CHECKRECORD" :1 ,"id" : id}, function(data){
if (data = 1) {
alert("This attraction has already been added to your itinerary")
handleModalClose();
} else if (data = 0){
$.ajax({
url: 'php/itinerary.php',
type: 'POST', //will send a POST request to the PHP back-end with the "attractionId" the user has clicked on
dataType: 'json',
data: {
action: 'CREATE',
attractionId: $(ev.target).parents('div.Attraction')[0].$data.attraction_id //The $(ev.target).parents('div.attraction')[0].$data.attraction_id expression get's the "attractionId" of the clicked element
},
//It first get's the parent div with the class "attraction" reads the first one in the list [0] and then reads the $data property of this element
success: function(data) {
alert("The attraction is successfully added");
},
error: console.log
});
}
});
}