I'm having trouble with my ajax call not working properly. Can anyone help me identify what might be missing in my code?

const userId = window.localStorage.getItem("zicuserId");
const dataString = "deviceId="+myDeviceId + "&userId=" + userId + "&deviceToken=" + myDeviceToken;
alert("dataString: " + dataString);
$.ajax({
        type: POST,
        url: "http://mobilapps.zicoil.pk/fineName.php",
        data: dataString,
        async: false,
        dataType: "text",
        success: function(data)
        {
            window.localStorage.setItem("userDeviceRegister", "true");
            alert(data);
        },
        error: function()
        {
            alert("error , you are in error function.")
        }
    });

Answer №1

Give this a try.

let userID = window.localStorage.getItem("zicuserId");
let dataObject = {deviceId: myDeviceId, userId: userId, deviceToken: myDeviceToken};
alert("dataString: " + JSON.stringify(dataObject));
$.ajax({
    url: "http://mobilapps.zicoil.pk/fineName.php",
    type: "POST",
    data: dataObject,
    async: false,
    dataType: "JSON",
    success: function(data) {
        window.localStorage.setItem("userDeviceRegister", true);
        alert(data);
    },
    error: function() {
        alert("An error occurred. You are in the error function.");
    }
});

Answer №2

There is a syntax error in this line: type: POST,. Simply replace POST with "POST". This parameter should be a string, as it is currently an undefined variable.

By the way, using the browser console can help you identify these types of errors more easily.

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

What could be causing the state variable to fail to update in React?

Whenever a certain condition is met, a state variable should be updated. However, whenever it enters the if statement, the index remains at 0. import React, { useState, useEffect } from 'react'; import { words } from "./words.json"; im ...

Navigating the use of PHP variables in JavaScript

Whenever I select an option from the menu, a Javascript function changes the input value based on a PHP variable. Below is an example of how I assign values from 1 to n to each option: $i = 0; foreach($videos as $val) { echo '<option value=&ap ...

Issues with cross-domain AJAX JSONP requests not functioning in Internet Explorer 8

After enabling CORS support using jquery-1.9.1, I made an ajax request with jsonp callback support from the server side. $.ajax({ type: 'GET', url: url, async: false, contentType: "application/json", jsonpCallback: 'jso ...

No changes will be made to the database entry

Currently facing an issue where no values are being updated on a specific ID as specified (hardcoded) in the WHERE clause. Can anyone point out what might be going wrong? I have a form with 7 fields to fill out. At the moment, I am focusing on getting th ...

Is there a way to show additional information beyond just the title in FullCalendar?

Hello, I am currently using the full calendar plugin and have a question. While I can display the title of events on my calendar, I would also like to display additional information from my database (such as full name or description) alongside the title. H ...

Utilizing the loop counter within an Array

Currently, I am attempting to iterate through numbers 1 to 21 and then utilize those numbers in order to obtain an Array of Strings like ['e1.wkh',...'e21.wkh']. However, at the moment I am only receiving the value ['e21.wkh'] ...

Preserving the video's aspect ratio by limiting the width and height to a maximum of 100%

I am trying to integrate a YouTube video using their embed code in a "pop-up". However, I am facing an issue where the video does not resize to fit within the height of its parent. I want it to be constrained by the div#pop-up that contains the video. Curr ...

Encountering a hitch while attempting to integrate a framework in Angular JS 1

Having experience with Angular JS 1 in my projects, I have always found it to work well. However, I recently encountered a project that uses Python and Django, with some pages incorporating Angular. The specific page I needed to work on did not have any An ...

Is there a way to use JavaScript to open a new window that appears on top of all others?

When you open a window like this alongside a notepad, the new window appears below the notepad. I am curious about how to make a new window open on top of all other windows. Using window.focus() does not seem to do the trick.. setTimeout(function() { ...

Ways to repair the mouse hover transform scale effect (animation included)

I am currently facing an issue with my GridView that contains images. When I hover over the top of the image, it displays correctly, but when I move to the bottom, it does not show up. After some investigation, I suspect that there may be an overlay being ...

How can I turn off the animation for a q-select (quasar select input)?

I'm just starting out with Quasar and I'm looking to keep the animation/class change of a q-select (Quasar input select) disabled. Essentially, I want the text to remain static like in this image: https://i.stack.imgur.com/d5O5s.png, instead of c ...

What is the best way to retrieve a date (value) from a DatePicker and then set it as a property in an object

I am currently utilizing the react-datepicker library, and I have a question about how to retrieve a value from the DatePicker component and assign it to the date property within the Pick object. Extracting data from regular input fields was straightforw ...

Laravel experiences compatibility issues with AJAX functionality when running on an Apache server

After successfully running this code using php artisan server, everything seems to be working fine. However, when attempting to use Apache, a 404 response is encountered. Let's take a closer look at the code fragments: Ajax: $('.item_tr ...

Transfer data from a Telerik Grid to a form action in MVC

I am facing a unique challenge that has been difficult to solve so far. The issue I'm dealing with involves a form that contains various textboxes, dropdown lists, and other elements. These elements are posted back through the model attached in the v ...

Elements are unresponsive to scrolling inputs

My Ionic 2 input elements are not scrolling to the top when the keyboard is shown. I've tried everything I could find on Google, making sure the keyboard disable scroll is set to false. However, I still can't figure out what's causing the sc ...

When using selenium with python, the function excecute_script('return variable') may not technically return variables, even though the variable does exist

My attempt to retrieve a variable from javascript code using selenium is encountering difficulties. Despite the presence of the variable (confirmed by inspecting the source code before executing the script), the command driver.execute_script('return v ...

Delayed Passport Session Login

Every time I try to log in, my Express app loads very slowly... I've implemented Passport and Express Validator, but there are no errors. However, the login process for some users is extremely slow. Can anyone offer assistance? Below is a snippet o ...

Label the timeline map generated with the leaftime plug-in for leaflet in R with the appropriate tags

Here is a code snippet extracted from the R leaftime package documentation examples. It generates a map with a timeline that displays points as they appear over time. I am interested in adding labels to these points to show their unique id numbers. Upon ...

Obtain the date value in the format of month/day/year

How can I retrieve the date from 2 months ago and format it as MM/DD/YYYY? I tried this code snippet, but it's returning a value in the format "Tue Feb 11 14:30:42 EST 2014". var currentDate = new Date(); currentDate.setMonth(currentDate.getMonth() ...

How can images be resized according to screen resolution without relying on javascript?

Looking to use a large banner image on my website with dimensions of 976X450. How can I make sure that the image stretches to fit higher resolution monitors without using multiple images for different resolutions? ...