iron ajax 没有将输入数据发布到 php
iron ajax not posting input data to php
部分聚合物元素脚本:
<content>
<iron-ajax id="plWhois" method="POST" body='{"helper":"plugin", "func":"_pluginsInitAjax", "params":{"domain": "domain", "request_type": "taken"}}' handle-as="json" on-response="handleResponse" debounce-duration="300"></iron-ajax>
<paper-card heading="Begin the search for your perfect domain name..." image="themes/custom_components/apps/pl-whois/img/who-is.jpg" center>
<div class="card-content">
<paper-input id="plWhoisSearchBtn" type="search" placeholder="e.g. mydomain.com">
<iron-icon prefix icon="search"></<iron-icon>
</paper-input>
</div>
<div class="card-actions s-t">
<paper-button on-click="domainAvailability">Search</paper-button>
<paper-button>Transfer</paper-button>
</div>
<div class="card-actions p-l">
<paper-button>buy a domain</paper-button>
<paper-button>order hosting</paper-button>
<paper-button>make payment</paper-button>
<paper-button>support</paper-button>
</div>
</paper-card>
</content>
<script>
// element registration
Polymer({
is: "pl-whois",
properties: {
url: {
type: String,
notify: true,
value: ''
},
body: {
type: Object,
notify: true,
value: ''
}
},
domainAvailability: function () {
var domain = this.$.plWhoisSearchBtn.value;
this.$.plWhois.url = "ajax.php";
/*this.$.plWhois.body = {"helper":"plugin", "func":"_pluginsInitAjax", "params":{"domain": domain, "request_type": "taken"}};
*/
this.$.plWhois.generateRequest();
},
handleResponse: function(e) {
console.log(e.detail.response);
}
});
</script>
问题是,上面的元素是导入的,我使用以下方法从聚合物中获取 post 数据:
$json = file_get_contents("php://input");
$_POST = json_decode($json, true);
我得到了
none 导入的脚本工作正常,它们 post 数据,但是导入的脚本执行 ajax 请求但不 post 数据到 php.
您的 <iron-ajax>
调用似乎缺少 url
属性。
我仍然遇到同样的问题,看起来像是错误或其他问题(动态导入的脚本不会在 iron-ajax 请求期间发送 post 数据)。
因此,作为一种解决方法,从元素的属性中获取 url 和正文值,然后将它们绑定到 iron ajax 似乎可行:
Iron-ajax:
< iron-ajax id="plWhois" method="POST" url="{{url}}" body='{{params}}' handle-as="json" on-response="handleResponse" debounce-duration="300">< /iron-ajax>
此脚本将属性添加到我的元素并触发 iron 请求:
var domain = this.$.plWhoisSearchBtn.value;
this.url = 'ajax.php';
this.params = '{"helper":"plugin", "params":{"0":"whoapi_dot_com", "1":"_test", "2":{"0": "'+domain+'", "1": "taken"}}}';
this.$.plWhois.generateRequest();
现在我导入的元素是这样的(部分):
//imports
<dom-module id="pl-whois" class="wide-layout-mq">
<template>
<style></style>
<iron-ajax id="plWhois" method="POST" url="{{url}}" body='{{params}}' handle-as="json" on-response="handleResponse" debounce-duration="300"></iron-ajax>
<content>
<paper-card heading="Begin the search for your perfect domain name..." image="themes/custom_components/apps/pl-whois/img/who-is.jpg" center>
<div class="card-content">
<paper-input id="plWhoisSearchBtn" type="search" placeholder="e.g. mydomain.com" on-keyup="updateParams">
<iron-icon prefix icon="search"></<iron-icon>
</paper-input>
</div>
<div class="card-actions s-t">
<paper-button on-click="domainAvailability">Search</paper-button>
<paper-button>Transfer</paper-button>
</div>
<div class="card-actions p-l">
<paper-button>buy a domain</paper-button>
<paper-button>order hosting</paper-button>
<paper-button>make payment</paper-button>
<paper-button>support</paper-button>
</div>
</paper-card>
</content>
</template>
<script>
// element registration
Polymer({
is: "pl-whois",
properties: {
url: {
type: String,
notify: true,
reflectToAttribute: true,
value: ''
}
},
updateParams: function (e) {
var domain = this.$.plWhoisSearchBtn.value;
this.url = 'ajax.php';
this.params = '{"helper":"plugin", "params":{"0":"whoapi_dot_com", "1":"_test", "2":{"0": "'+domain+'", "1": "taken"}}}';
if(e.keyCode === 13){
this.$.plWhois.generateRequest();
}
},
domainAvailability: function () {
var domain = this.$.plWhoisSearchBtn.value;
this.url = 'ajax.php';
this.params = '{"helper":"plugin", "params":{"0":"whoapi_dot_com", "1":"_test", "2":{"0": "'+domain+'", "1": "taken"}}}';
this.$.plWhois.generateRequest();
},
handleResponse: function(e) {
console.log(e.detail.response);
}
});
</script>
希望这对同样被困的人有所帮助!
部分聚合物元素脚本:
<content>
<iron-ajax id="plWhois" method="POST" body='{"helper":"plugin", "func":"_pluginsInitAjax", "params":{"domain": "domain", "request_type": "taken"}}' handle-as="json" on-response="handleResponse" debounce-duration="300"></iron-ajax>
<paper-card heading="Begin the search for your perfect domain name..." image="themes/custom_components/apps/pl-whois/img/who-is.jpg" center>
<div class="card-content">
<paper-input id="plWhoisSearchBtn" type="search" placeholder="e.g. mydomain.com">
<iron-icon prefix icon="search"></<iron-icon>
</paper-input>
</div>
<div class="card-actions s-t">
<paper-button on-click="domainAvailability">Search</paper-button>
<paper-button>Transfer</paper-button>
</div>
<div class="card-actions p-l">
<paper-button>buy a domain</paper-button>
<paper-button>order hosting</paper-button>
<paper-button>make payment</paper-button>
<paper-button>support</paper-button>
</div>
</paper-card>
</content>
<script>
// element registration
Polymer({
is: "pl-whois",
properties: {
url: {
type: String,
notify: true,
value: ''
},
body: {
type: Object,
notify: true,
value: ''
}
},
domainAvailability: function () {
var domain = this.$.plWhoisSearchBtn.value;
this.$.plWhois.url = "ajax.php";
/*this.$.plWhois.body = {"helper":"plugin", "func":"_pluginsInitAjax", "params":{"domain": domain, "request_type": "taken"}};
*/
this.$.plWhois.generateRequest();
},
handleResponse: function(e) {
console.log(e.detail.response);
}
});
</script>
问题是,上面的元素是导入的,我使用以下方法从聚合物中获取 post 数据:
$json = file_get_contents("php://input");
$_POST = json_decode($json, true);
我得到了
none 导入的脚本工作正常,它们 post 数据,但是导入的脚本执行 ajax 请求但不 post 数据到 php.
您的 <iron-ajax>
调用似乎缺少 url
属性。
我仍然遇到同样的问题,看起来像是错误或其他问题(动态导入的脚本不会在 iron-ajax 请求期间发送 post 数据)。
因此,作为一种解决方法,从元素的属性中获取 url 和正文值,然后将它们绑定到 iron ajax 似乎可行:
Iron-ajax:
< iron-ajax id="plWhois" method="POST" url="{{url}}" body='{{params}}' handle-as="json" on-response="handleResponse" debounce-duration="300">< /iron-ajax>
此脚本将属性添加到我的元素并触发 iron 请求:
var domain = this.$.plWhoisSearchBtn.value;
this.url = 'ajax.php';
this.params = '{"helper":"plugin", "params":{"0":"whoapi_dot_com", "1":"_test", "2":{"0": "'+domain+'", "1": "taken"}}}';
this.$.plWhois.generateRequest();
现在我导入的元素是这样的(部分):
//imports
<dom-module id="pl-whois" class="wide-layout-mq">
<template>
<style></style>
<iron-ajax id="plWhois" method="POST" url="{{url}}" body='{{params}}' handle-as="json" on-response="handleResponse" debounce-duration="300"></iron-ajax>
<content>
<paper-card heading="Begin the search for your perfect domain name..." image="themes/custom_components/apps/pl-whois/img/who-is.jpg" center>
<div class="card-content">
<paper-input id="plWhoisSearchBtn" type="search" placeholder="e.g. mydomain.com" on-keyup="updateParams">
<iron-icon prefix icon="search"></<iron-icon>
</paper-input>
</div>
<div class="card-actions s-t">
<paper-button on-click="domainAvailability">Search</paper-button>
<paper-button>Transfer</paper-button>
</div>
<div class="card-actions p-l">
<paper-button>buy a domain</paper-button>
<paper-button>order hosting</paper-button>
<paper-button>make payment</paper-button>
<paper-button>support</paper-button>
</div>
</paper-card>
</content>
</template>
<script>
// element registration
Polymer({
is: "pl-whois",
properties: {
url: {
type: String,
notify: true,
reflectToAttribute: true,
value: ''
}
},
updateParams: function (e) {
var domain = this.$.plWhoisSearchBtn.value;
this.url = 'ajax.php';
this.params = '{"helper":"plugin", "params":{"0":"whoapi_dot_com", "1":"_test", "2":{"0": "'+domain+'", "1": "taken"}}}';
if(e.keyCode === 13){
this.$.plWhois.generateRequest();
}
},
domainAvailability: function () {
var domain = this.$.plWhoisSearchBtn.value;
this.url = 'ajax.php';
this.params = '{"helper":"plugin", "params":{"0":"whoapi_dot_com", "1":"_test", "2":{"0": "'+domain+'", "1": "taken"}}}';
this.$.plWhois.generateRequest();
},
handleResponse: function(e) {
console.log(e.detail.response);
}
});
</script>
希望这对同样被困的人有所帮助!