jQuery AJAX 调用 Slim 框架

jQuery AJAX call to Slim Framework

我正在尝试在我的项目中使用 Slim,但我无法正确设置 AJAX 调用:

$.ajax({
        url: "/api/addresses/",
        type: 'POST',
        contentType: 'application/json',
        dataType: 'json',
        data: {QID: QID, departmentID: departmentID}
        },
        error: function(err) {
            alert(err.statusText);
        },
        success: function(data) {

        ...

我的 Slim 文件如下所示:

require_once('Slim3.php');

function loadEndpoint()
{
    global $app;

    //fetch
    $app->post('/addresses', function($request, $response, $args){
        $objDB = new DB;
        $json = $objDB
            -> setStoredProc("canvas_fetch_module_department_addresses")
            -> setParam("QID", $args['QID'])
            -> setParam("departmentID", $args['departmentID'])
            -> execStoredProc()
            -> parseXML();
        return $response->write($xml);
    });
}

我什至没有看到在我的控制台中进行的 AJAX 调用,所以我认为这就是问题所在。设置有什么值得注意的地方吗?

我在使用 AJAX 和 SLIM 时遇到了同样的问题:

从调用 URL 中删除“/”“/api/addresses”

如果 API 没有错误,我希望这能解决您的问题?

阅读此内容了解更多详情:http://help.slimframework.com/discussions/problems/7071-optional-route-parameters-force-either-or-no-in-urls