continues to display the identical alert notification, regardless of whether it has been included or not

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
}); 
    }
});
}

Answer №2

Always remember to utilize if(data == 0) instead of if(data = 0). A single = assigns the value to the variable whereas double equals compares them.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an infinite loop animation using GSAP in React results in a jarring interruption instead of a smooth and seamless transition

I'm currently developing a React project where I am aiming to implement an infinite loop animation using GSAP. The concept involves animating a series of elements from the bottom left corner to the top right corner. The idea is for the animation to sm ...

Tips on customizing the default dropdown icon in a select list

Does anyone know of a website or code snippet that offers source code for customizing select elements? I am looking to replace the default dropdown icon with an image. Any suggestions? Thank you! ...

handling data in multipart/form format

When attempting file upload using XMLHttpRequest() in my jsp, the result of request.getContentType() in my controller is: multipart/form-data; boundary=---------------------------4664151417711. I am unsure how to retrieve and access the contents of the u ...

"The variables in the .env file are not reflecting the latest updates. What is the best way

Currently, I am in the process of developing an application using Quasar (Vue) where I have stored my database keys in a .env file. Recently, I encountered an issue when attempting to switch to another instance and updating the keys in the env file. Despit ...

Do I need to include both the JavaScript and CSS CDN for the bootstrap CDN to work properly, or can I just use one of them?

Which resource should I use for my project? Should I go with CSS, JS, BUNDLE or all of them? https://i.sstatic.net/0Yi3F.png I am interested in using button styling, grid, card components (and possibly dropdowns in the future) https://cdn.jsdelivr.ne ...

Differences in Angular.js/jQuery html string parsing between versions 1.9.1 and 1.8.3

When attempting to use angular.element(stringWithHtmlStructure);, an error is thrown: Error: Syntax error, unrecognized expression: <div id="foo">bar</div> This issue occurs in jQuery 1.9.1 but not in 1.8.3. Is this a bug or a deliberate sec ...

The DOM seems to be producing NaN when receiving user input

Currently, I am in the process of developing a depreciation calculator that utilizes user input fields to generate an alert with the resulting value. When I set the variables to predefined test values without incorporating user input, the calculator funct ...

Creating a personalized pathway for accessing a user's settings

Oops! Looks like there's an error: An element is only ever to be used as the child of another element, never rendered directly. Please make sure to wrap your element in a proper container. Custom Private Router Component function PrivateRoute({ child ...

Loop through an array of objects that each contain two sub-objects using ng

I'm looking to organize each data-record in an object that contains two other objects structured like this: data Object { abbData={...}, invoiceData={...}} abbData Object { service="24", conn_fee="0", month_fee="249", more...} invoiceData ...

Troubleshooting the Confirm Form Resubmission problem on my website

Hello everyone! I'm working on a website and facing an issue where refreshing the page triggers a confirm form resubmission prompt. Could someone please advise me on how to resolve this? Thank you in advance! ...

Utilizing Datepicker in CodeIgniter to Implement Server-Side Date Range Filtering with Datatables

Seeking urgent assistance. After weeks of trying various codes sourced online, I am still unable to implement Datatables serverside date range functionality using Codeigniter with the date picker. Whenever the selected dates differ, I end up with a range s ...

Loading Google Maps with Ajax

Exploring the world of google maps has been quite entertaining for me, however, I find myself in need of some assistance. The issue at hand involves a small block of HTML/Javascript that can be seamlessly integrated into a standard HTML page or loaded into ...

`Implementing AJAX data binding in a Flask Python Application`

I am currently laying the groundwork for my first Python Flask web application. While I have the server-side details sorted out, I have some queries regarding the client-side implementation. The application I am working on will be a single-page applicatio ...

Is it necessary to display a div if the chosen Datatables row contains a span?

Currently, I am dealing with a table that has attachments, but for illustration purposes, I'm using a copyright icon. My challenge lies in displaying or hiding the .newImage block based on whether the row contains a span element (copyright icon) when ...

Triggering JavaScript Function When Scrolling in Overflowed DIV

After using jQuery and searching for various ways to make this script work, I finally found a solution that works for my index.html file. <div style="overflow-y:scroll; height:300px"> <div style="background-color:black; height:500px"> </div ...

Assess the iOS app on Meteor to establish a live connection with an authentic server (not the local host)

Testing my Meteor application on an iOS phone has been a learning experience. Following the steps outlined in this guide, I initially deployed the app with the commands: meteor install-sdk ios meteor add-platform ios meteor run ios meteor run ios-dev ...

My Rails application is having trouble rendering the .js.erb file

Within my create.js.erb file, the following code is present: pollingAJAX(); function pollingAJAX() { $.ajax({ method: "POST", url: "/status", data: {uuids: '<%= @uuid_hash.to_json %>'}, }, succ ...

Issues with the functionality of materials in three.js causing lighting problems

After much experimentation, I am still struggling to achieve a normal shadow using Spot and Directional lights with Lambert and Phong materials: Take a look at some examples When using Spot Light with Lambert Material, the material does not react to ligh ...

Validation of default values in contact forms

Obtained a free contact form online and hoping it works flawlessly, but struggling with validation for fields like "Full Name" in JS and PHP. Here is the HTML code: <input type="text" name="contactname" id="contactname" class="required" role="inpu ...

Unlimited possibilities with parameters on an express server

I've set up React Router with recursive parameters, similar to the example here. On my Express server, I'm attempting to handle routes like /someRoute/:recursiveParameter? router.get('/someRoute/:recursiveParameter?', async (req, res ...