Error: The function this.$.AjaxPost.go is missing or not recognized in the core-ajax module

Recently, I created an HTML page for handling Password Reset functionality on our website. We have decided to make POST calls to the server and are implementing it using polymer. Below is a snippet of the code:

<dom-module id="user-password-reset">

<template>
    <div class="popup">

        <h5 class="popup-heading">Forgot Password</h5>

        <div class="popup-body">
            <div class="form-group">
                <label for="FormInput-UserEmail">Provide your Email Address</label>
                <input type="email" class="form-control" id="FormInput-UserEmail" placeholder="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8de3ece0e8cde8f5ece0fde1e8a3eee2e0">[email protected]</a>" value="{{ email::input }}">
            </div>
            <br/>
            <div class="text-center">
                <button type="button" class="btn" on-click="onSubmit">Reset Password</button>
            </div>
        </div>

    </div>

    <core-ajax
        id="AjaxPost"
        auto="false"
        url="/api/user/email"
        method="POST"
        content-type="application/json"
        handle-as="json"
        on-core-response= _handleAjaxPostResponse
        on-core-error= _handleAjaxPostError
        ></core-ajax>

</template>


<script>
    Polymer({

        is: 'user-password-reset',

        behaviors: [
            Polymer.IronOverlayBehavior
        ],

        properties: {
            email: { type: String },
        },

        onSubmit: function( event ) {
            this.$.AjaxPost.params = JSON.stringify( { email: this.email } );
            console.log( this.$.AjaxPost );
            this.$.AjaxPost.go();
        },

        _handleAjaxPostResponse: function( event ) {
            /* Do Something */
        },

        _handleAjaxPostError: function( event ) {
            /* Do Something */      
        },
    });

</script>

</dom-module>

In the console :

<core-ajax id="AjaxPost" auto="false" url="http://localhost:8080/api/user/email" method="POST" content-type="application/json" handle-as="json" class="style-scope user-password-reset"></core-ajax>

An error message is displayed:

Uncaught TypeError: this.$.AjaxPost.go is not a function

I am seeking advice on how to resolve this issue. What steps should I take next?

Answer №1

Apologies for the oversight, I neglected to specify that we are using Polymer 1.0. Thanks to Ben Thomas for bringing that to my attention. The solution ended up being quite simple - there was no need to convert it to JSON and use iron-ajax instead of core-ajax.

Here is the code snippet:

<iron-ajax
        id="AjaxPost"
        url="/api/user/email"
        method="POST"
        content-type="application/json"
        handle-as="json"
        on-response="_handleAjaxPostResponse"
        on-error="_handleAjaxPostError"
        ></iron-ajax>

var ajaxPost = this.$.AjaxPost;
            ajaxPost.params = { email: this.email };
            ajaxPost.generateRequest();

It's worth noting that when making POST calls, it's better to send the data in params rather than in the body (I read this somewhere). Also, while sending it, do not stringify it as JSON.

Answer №2

Some time ago, I encountered a similar issue.

You might want to consider utilizing the noConflict() method, as it could be that there is a conflict between your current javascript library and jQuery.

I found this resource helpful: https://api.jquery.com/jquery.noconflict/

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

tap the hyperlink to complete the form and mimic the action of a designated

I'm working on an HTML form that includes a table and two submit buttons. <input type="image" name="button1" value="First Button" src="some_image.png"> <input type="image" name="button2" value="Second Button" src="some_image.png"> One ch ...

Having trouble retrieving cookie in route.ts with NextJS

Recently, I encountered an issue while using the NextJS App Router. When attempting to retrieve the token from cookies in my api route, it seems to return nothing. /app/api/profile/route.ts import { NextResponse } from "next/server"; import { co ...

What are some techniques for styling a field when the div id is not specified?

I need to customize a data field within a table, but I am unable to locate or identify its div ID. Here is the page source: <tbody> <tr> <td style="font-size:12px; text-align:center;" name=""> <div sty ...

Is there a way for me to identify when I am "traveling" along the same path?

I want to create a toggle effect where a view is hidden if the user tries to revisit it. This can be useful for showing/hiding modal boxes. Here's the code I attempted: /* Root Instance */ const app = new Vue({ router, watch: { '$route&a ...

Passing arguments to the callback function in React: a comprehensive guide

Within my react component, I have a collection of elements that I want to make clickable. When clicked, I trigger an external function and pass the item ID as an argument: render () { return ( <ul> {this.props.items.map(item => ( ...

What is the best way to customize the appearance of chosen selections in the MUI Autocomplete component?

I'm currently facing an issue with changing the style of selected options in MUI when the multi option is enabled. My goal is to alter the appearance of all highlighted options. Any assistance on this matter would be greatly appreciated, thank you! ...

Countdown to redirect or exit on Jquery mobile "pageshow" and "pagehide" events

Looking to implement a 30-second countdown on a Jquery Mobile page with specific requirements: (1) Countdown begins on pageshow (2) Redirects to new page when countdown expires (3) If user navigates away (pagehide) before countdown finishes, the timer fun ...

Prevent AJAX request while in progress?

I've made some adjustments to a jQuery Autocomplete plugin, which now retrieves a JSON object from a MySQL database instead of an array. However, I've noticed that each time I click on the input field, it triggers a new request, even if it&apos ...

Is it possible to add information to the form data object?

When I send an image to the server using form data, everything seems fine until I try to add data from a crop plugin. Here is the code snippet: //create form data from form var formData = new FormData($('#my-form')[0]); //append the image formD ...

What is preventing me from invoking the function that I built using the Function() constructor?

Utilizing the Function Constructor within a function to generate functions during its call. Below is the constructor: funcGenerator(f) { return new Function( "value", "try{ return " + f + '; } catch (e) { ret ...

Internet Explorer 11 Freezes Unexpectedly with Dynamic SVG Components

Lately, I developed a unique SVG Icon control for the new html application at my workplace. However, our quality department started noticing that IE 11 would intermittently "crash" while using the application after its implementation. I'm not convinc ...

What could be the reason for my React/HTML select element occasionally failing to display the default selected value?

I am currently working on creating a select element in Reactjs/HTML and I am facing an issue with setting a default value based on a component variable. Essentially, the default value of the select should be the id of a component. This is my current imple ...

Understanding how to access a variable outside of a function in Node.js can be crucial for successfully passing

I am trying to figure out how to access the TRADE_OUT variable outside of a specific function in my application. Despite my efforts, I haven't been successful so far. I need the value of TRADE_OUT to be globally accessible within the entire applicatio ...

Trouble with retrieving dates in ISO format

My collection stores the date of birth field in ISO format, for example: ISODate("1980-01-01T20:20:19.198Z") However, when I use a date time picker on my HTML page, it displays the date like this: 01/01/1980 Unfortunately, when querying for the date of ...

Can you share tips for passing a variable from a post request to a function that accepts parameters as a string or an array of strings in Node.js?

I am struggling to insert the variable named query into the end of the prompt. I attempted to use template literals but it was unsuccessful. (async () => { const gbtResponse = await openai.createCompletion({ model: "text-davinci-002", prompt ...

What strategies can I employ to access data from an Ajax POST call beyond its original return function?

I am facing an issue with my jQuery Ajax POST call that runs a PHP script and retrieves data. The problem lies in accessing this data outside the success function. Even though I have declared a global variable components, it seems to lack scope within the ...

What is the best method for determining the cookie expiration time in AngularJS 1.3?

Currently in my application, I am utilizing AngularJS 1.3. I encountered a challenge while using $cookies to store data where I needed to implement a 1-minute expiration time for the cookie. However, the $cookies service in AngularJS 1.3 does not provide ...

Discover the ultimate strategy to achieve optimal performance with the wheel

How can I dynamically obtain the changing top position when a user moves their mouse over an element? I want to perform some checks whenever the user scrolls up, so I tried this code: HostListener('window:wheel', ['$event']) onWindowS ...

During post-processing, the elimination of lens flares can sometimes lead to an error known as "copyTexImage2D: framebuffer is

After looking at the lens flares example here: , I'm encountering an issue with post-processing this particular scene. The blocks display correctly, but the light sources and lens flares are missing. Additionally, I am receiving several warnings in t ...

Switch between various components using multiple buttons in Next.js

I am in the process of creating a component that will display different components depending on which button the user selects. Here are the available “pages”: ` const navigation = [ { name: "EOQ", return: "<EOQgraph />" }, { nam ...