javascript - 通过jquery调用对象函数
问题描述
大家好,我想公开一个问题......我的网络应用程序有这种情况:
//路线
getRoute()->post('/aggiungiMateria', array("GestioneController","aggiungiMateria"));
//控制器
function aggiungiMateria(){
try{
$model = new GestioneModel();
$alunno = $model->aggiungiMateria();
echo 'ok';
}catch(Exception $e){
echo json_encode(array($e->getMessage()));
}
}
//模型
function aggiungiMateria(){
$nome = addslashes($_POST['nome']);
try{
$db = $this->getConnection();
$query = $db->prepare("INSERT INTO materie SET nome = '$nome' ");
$query->execute();
}catch(PDOException $e){
echo $e->getMessage();
}
}
//HTML
<label>Materia</label>
<input type="text" id="nome" value="<?php echo $materia;?>" />
<input type="hidden" id="controllo" value="<?php echo $id?>"/>
<button onclick="gestione();">SALVA</button>
//JS AJAX
function gestione(){
$('.loading').show();
var nome = $('#nome').val();
var id = $('#controllo').val();
if(id!=''){
$.post( "../../ws/modificaMateria", { //NOT FOUND
nome:nome,
id:id
},
function( data ) {
if(data=='ok'){
location.href='materie.php';
}
}, "html");
}else{
$.post( "../../ws/aggiungiMateria", { //NOT FOUND
nome:nome,
id:id
},
function( data ) {
if(data=='ok'){
location.href='materie.php';
}
}, "html");
}
}
当单击 SALVA 按钮时,调试器会抛出 /ws/aggiungiMateria 的异常,错误 404 和来自 jQuery-2.1.4.min 的 f.send 给我来自 chrome 开发工具的未捕获错误。对于这篇文章中的任何错误,我深表歉意。
有什么建议吗?提前致谢。
解决方案
我通过使用 AllowOverride All 指令修改 apache 配置文件来解决
推荐阅读
- node.js - 在 NodeJS/ElectronJS 中控制多媒体
- python - 对 Django Taggit 的自动完成库的建议
- c - \v 垂直制表符在 C 中不起作用(显示男性性别符号)
- html - div填充图像引导css
- css - 反应打印页面内容
- java - “DiscordApi 无法解析为类型” Discord Java Eclipse Bot
- flask - 从Flask中的html标签传递参数到视图函数有什么区别?
- reactjs - 如何将动态值传递给 getStaticPaths
- java - 将动画添加到android
- javascript - JS根据其他输入值自动计算输入字段不起作用