未捕获的类型错误:this.$.AjaxPost.go不是一个以函数为核心的ajax
Uncaught TypeError: this.$.AjaxPost.go is not a function - core-ajax
我为我们的网站编写了一个用于密码重置的HTML页面,我们希望它是对服务器的POST调用。我们使用的是聚合物,代码:
<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="name@example.com" 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>
控制台中:
<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>
有一个错误说:
Uncaught TypeError: this.$.AjaxPost.go is not a function
我现在该怎么办?
对不起,我忘了提到聚合物的版本。我们使用Polymer 1.0,感谢Ben Thomas指出这一点。解决方案很简单,不需要将其转换为Json,也不需要使用iron ajax来代替核心ajax。
代码:
<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();
请注意,如果您使用Post调用,那么最好以params形式发送数据,而不是以body形式发送数据(在某处读取)。发送时,不要将其字符串化。
有时我已经遇到了这个问题。
请尝试使用noConflict()
,因为jquery可能与您正在运行的WHAT冲突。
此页面帮助了我:https://api.jquery.com/jquery.noconflict/
相关文章:
- 如何将一个JavaScript函数回调为多个函数
- 代码背后调用一个JavaScript函数的按钮点击-C#
- 为什么window.open不打开一个以变量形式给出的链接
- 多次调用另一个javascript函数中的javascript函数
- 我如何制作一个JS函数,它可以从相似的原始颜色双向更改为某个颜色
- 在任何AJAX调用之前触发一个javascript函数
- 可以定义一个中缀函数吗
- 另一个Ajax函数触发的Ajax函数不起作用
- 我需要一个jQuery函数来只工作在700px以上的屏幕大小,无法在我的代码中发现错误
- 添加一个javascript函数来下载elfinder上的事件
- 带有一个具有函数的参数的Javascript函数
- 如何制作一个JavaScript函数,处理多组输入,以同样的方式进行数学处理
- 谷歌表格图表:编写了一个计算函数,添加了以前点击的单元格,而不是当前的单元格
- 未捕获的类型错误:this.$.AjaxPost.go不是一个以函数为核心的ajax
- 在作用域外编写一个 Javascript 函数以在作用域内触发
- 为什么console.trace()的结果以一个“匿名函数”结束?这个函数是什么?
- 如何以组的方式调用一个异步函数?
- 向页面的当前URL添加一个参数,该参数在另一个Javascript函数中解析,以在页面上定位
- GraphQL错误字段必须是一个以字段名作为键的对象,或者是一个返回这样一个对象的函数
- 用While Loop &构建一个以年递增月份的函数;Momentjs