我目前有node.js版本0.8.8,并安装了npm 1.1.59.
每当我跑:
$ npm install -g express
Run Code Online (Sandbox Code Playgroud)
我得到了这个回报:
npm ERR! Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock'
npm ERR! { [Error: EACCES, open '/Users/devinandrews/.npm/64a534c1-express.lock']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/Users/devinandrews/.npm/64a534c1-express.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.1.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/devinandrews
npm ERR! node -v v0.8.8
npm ERR! npm -v 1.1.59
npm ERR! path /Users/devinandrews/.npm/64a534c1-express.lock
npm ERR! …Run Code Online (Sandbox Code Playgroud) 所以基本上我有我的骨干应用程序对我的苗条php应用程序进行ajax GET调用.它期望JSON dataType作为回报.
$.ajax({
url: './myroute',
type: 'GET',
dataType: "json",
data: { username: username, password: password },
success: function(data) {},
error: function(data) {}
});
Run Code Online (Sandbox Code Playgroud)
在我的苗条文件中,我有:
$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);
Run Code Online (Sandbox Code Playgroud)
虽然我的请求正确地通过(200),并且我正确地获取了我的JSON数据,但错误是因为它也返回完整的index.php页面数据(我的javascript dataType:"json"不允许,这触发了错误)
我认为将内容类型设置为"application/json"会解决这个问题,但它仍会返回整页内容以及json数据. …