Код: Выделить всё
$.ajax({
url: './myroute',
type: 'GET',
dataType: "json",
data: { username: username, password: password },
success: function(data) {},
error: function(data) {}
});
< /code>
В моем тонком файле у меня есть: < /p>
$app->get('/myroute', function() use ($app) {
// all the good stuff here (getting the data from the db and all that)
$dataArray = array('id' => $id, 'somethingElse' => $somethingElse);
$response = $app->response();
$response['Content-Type'] = 'application/json';
$response->body(json_encode($dataArray));
});
// Tried with these in the above GET request as well:
// $app->contentType('application/json');
// echo json_encode($dataArray);
I figured setting the content type to "application/json" would solve this, but it Все еще возвращает полное содержимое страницы, а также данные JSON.$app->get('/', function () use ($app) {
// would just have my main page files in home.php instead of index.php
$app-render('home.php');
});
< /code>
Таким образом, там не было никаких данных HTML -страницы, возвращаемых с index.php. Но то, как Pushstate, мне нужно, чтобы мои сценарии JavaScript работали на index.php, в противном случае мои страницы не будут загружены должным образом, так как, когда их просят, сценария нет, чтобы делегировать, куда должен идти.>
Подробнее здесь: https://stackoverflow.com/questions/141 ... rning-json
Мобильная версия