element, I am facing a dilemma with providing feedback to users. My goal is to notify users if they have already added something to their itinerary by displaying a message stating: "This attraction has already been added to your itinerary." However, even if the attraction has not been added yet, the message always appears. Strangely, there are no errors in the code. Does anyone have any insights into why this issue persists? Below is the function code that is causing this behavior.
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
});
}
});
}