【发布时间】:2019-04-10 01:36:02
【问题描述】:
我通过 PHP 查询从名为 BullHorn 的服务获取 JSON 对象,如下所示:
<?php echo getBhQuery('search','JobOrder','isOpen:true','id,title,categories,dateAdded,externalCategoryID,employmentType,customText12', null, 10, '-dateAdded');?>
但是,需要根据用户输入对 JSON 对象进行过滤。所以我在我的 Vue 应用程序中创建了获取用户输入值的输入,并且我试图将该值发布到 PHP。我的 Axios 代码如下所示:
onSubmit () {
axios.post('/wp-content/themes/bones/library/jobsResponse.php',{region: this.selectedLocation}, {headers: {'X-Requested-With': 'XMLHttpRequest', 'Content-type': 'application/x-www-form-urlencoded'}})
.then(function(response){
console.log(response)
})
.catch(function(error){console.log(error)})
}
所以这是在单击表单按钮时运行 onSubmit() 函数。然后使用 Axios 将数据发布到 jobsResponse.php 文件。目前它发布的数据是
this.selectedLocation
这就是我的 Vue 应用程序中的一个数据变量,它连接到用户可以使用的下拉输入。
那么在我的 jobsResponse.php 文件中我有:
$request_body = file_get_contents("php://input");
$data = json_decode($request_body, true);
$region = $data['region'];
所以它正在获取发布的数据并将其分配给 $region 变量。我最大的问题是更新 PHP 查询以添加过滤。要按区域过滤查询,我会将查询编辑为如下内容:
<?php echo getBhQuery('search','JobOrder','isOpen:true AND region:"Chicago Region"','id,title,categories,dateAdded,externalCategoryID,employmentType,customText12'); ?>
添加的所有内容都是“AND 地区:“芝加哥地区””,它只会获取地区设置为芝加哥地区的工作。因此,在我的 Vue 应用程序中,我有一个下拉输入,其中填充了用户可以过滤的所有区域。一旦选择了一个,我想获取该数据并使用 Axios 发布它并更新 PHP 查询以将过滤器添加到其中。
我一直在兜圈子,试图让它发挥作用,并在我所缺少的东西上碰壁。我相信我只是在尝试做一个类似 Ajax 的功能,但使用 Axios post 代替。
【问题讨论】:
标签: javascript php post vue.js axios