如何解决PHP Slim 405方法不允许
我是使用php苗条框架的新手,并且在以下方面苦苦挣扎:
我尝试-->post
和-->patch
都返回不允许的 405方法:POST(或PATCH,如果已修补)
$app->post('/export',function ($request,$response,$args) { // tried post and patch here
$which = $_POST['table'];
$db = $this->db;
$repo = new dataRepo($this->db);
if ($which == 'Table 1'){
$sql = 'SELECT * FROM app.table_1';
} else if ($which == 'Table 2'){
$sql = 'SELECT * FROM app.table_2';
} else if ($which == 'Table 3'){
$sql = 'SELECT * FROM app.table_3';
}
$stmt = oci_parse($this->db,$sql);
while (($row = oci_fetch_array($stmt,OCI_ASSOC)) != false) {
echo "<tr>";
foreach ($row as $columnName => $columnValue){
echo "<td>".$columnValue."</td>";
}
echo "</tr>";
}
$file = fopen($type + ".csv","w");
if (!@oci_execute($stmt)) {
$error = oci_error($stmt);
throw new Exception($error['message']);
}
});
下面是前端ajax调用..我在这里做什么错了?
$('#export' + '.' + crnt).click(function(){
let which = crnt; // console.logs as 'Table 1' or 'Table 2 or 3'
$.ajax({
url: "/export",data: { table:which },success: function(data){
console.log('success ninja');
}});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。