jQuery ajax()POST到Slim PHP框架 [英] jQuery ajax() POST to Slim PHP framework
本文介绍了jQuery ajax()POST到Slim PHP框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jquery mobile + phonegap,尝试发布到Slim应用程序中,我有以下代码:
Using jquery mobile+phonegap, trying to POST to a Slim application, I have this code:
$( document ).on( "vclick", "#test_form", function() {
$.ajax({
type: "POST",
url: "http://mydomain.com/slim/",
crossDomain: true,
beforeSend: function() {
$.mobile.loading('show')
},
complete: function() {
$.mobile.loading('hide')
},
data: {namec:$("#namec").val()},
dataType: 'json',
success: function(response) {
//console.error(JSON.stringify(response));
alert(response);
},
error: function() {
//console.error("error");
alert('Not working!');
}
});
});
我已经在其他非Slim PHP页面上对此进行了测试,并且一切正常,尽管Slim出现了Ajax错误.
I have tested this with other non Slim PHP pages and everything works fine, I get the ajax error with Slim though.
我的Slim应用:
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();
$app->post('/', function () {
echo json_encode($_POST("namec"));
});
$app->run();
刚开始使用Slim,所以不确定我会做错什么.
Just started using Slim, so not sure what I could be doing wrong.
推荐答案
您是否尝试过:
$app->post('/', function() use ($app) {
// ...
$req = $app->request();
echo json_encode($req->post('namec'));
//...
}
这篇关于jQuery ajax()POST到Slim PHP框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文