【发布时间】:2016-01-21 18:32:59
【问题描述】:
我正在使用 Polymer 的 Iron-Form 组件来提交我创建的这个表单,但问题是来自 php 脚本的响应不会输出到实际的 html。我坚持如何做到这一点,并尝试了许多不同的事情。我究竟做错了什么?这是我的脚本:
<dom-module id="user-signup">
<template>
<form is="iron-form" id="formGet" method="post" action="/core/register.php">
<paper-input char-counter autoValidate="true" error-message="{{item.error_name}}" label="Username" maxlength="25" required name="username"></paper-input>
<paper-input char-counter error-message="{{error_displayn}}" label="Display Name" maxlength="35" required name="displayname"></paper-input>
<paper-input char-counter error-message="{{error_password}}" label="Password" maxlength="25" required type="password" name="password"></paper-input>
<paper-input char-counter error-message="{{error_password}}" label="Confrim Password" maxlength="25" required type="password" name="cfmpassword"></paper-input>
<gold-email-input class="paper-input-input" label="Email" required name="email" auto-validate error-message="{{error_email}}"></gold-email-input>
<br />
<br>
<paper-button raised onclick="clickHandler(event)"><iron-icon icon="check"></iron-icon>Submit</paper-button>
</form>
</template>
<script>
function clickHandler(event) {
Polymer.dom(event).localTarget.parentElement.submit();
}
Polymer({
is: 'user-signup',
properties: {
error_name: {
type: String,
value:"Username Is Invalid!"
},
error_displayn: {
type: String,
value:"Display Name Is Invalid!"
},
error_password: {
type: String,
value:"Password Is Invalid!"
},
error_email: {
type: String,
value:"Email Is Invalid!"
}
},
listeners: {
'iron-form-response': 'formResponse',
'iron-form-submit': 'formSubmit',
'iron-form-error': 'formError'
},
formSubmit: function(event) {
var pmn = document.querySelector('#waitForResponse');
pmn.setAttribute("opened", "true");
console.log("Form was submitted");
},
formResponse: function(event) {
setTimeout(function(){
var pmn = document.querySelector('#waitForResponse');
pmn.removeAttribute("opened");
}, 5000)
console.log('There was a response');
var response = event.detail;
alert(response);
},
formError: function(event) {
console.log('Form Error, no actual response');
setTimeout(function(){document.querySelector('#errorToast').show();
var pmn = document.querySelector('#waitForResponse');
pmn.removeAttribute("opened");
}, 5000)
}
});
</script>
</dom-module>
现在侦听器开始工作,当 php 页面有响应时,会弹出警报,但它显示:[Object object]。这是php脚本:
<?php
$data[] = array(
"id" => $id,
"error_name" => $error_name,
"success" => true
);
echo 'dd';
?>
我尝试将$data 回显为 json,但也没有用。我试图在 Google 和 Stack 上搜索它,但没有找到任何东西。我做错了什么?
【问题讨论】:
-
实际连接服务器的xhr请求在哪里?接口是否实际上将 jsonRepose 放在 WIRE 上返回给客户端。为什么不 curl 发布登录并在进入聚合物代码之前对其进行测试
-
@RobertRowntree 当我按下提交时,它会向“/core/register.php?username=h&displayname=h&password=h&cfmpassword=h&email=hjk%40gklj.com”发出请求,响应为@ 987654327@这是一对截图screenshot 1screenshot 2
-
响应显示不合法的json
-
它的主链不是聚合物,但样本中的第 313 行可能有助于消耗响应 JSON github.com/ParsePlatform/Todo/blob/master/js/todos.js
标签: javascript php jquery polymer polymer-1.0