小编Dev*_*vin的帖子

npm不会安装快递?

我目前有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)

node.js express

46
推荐指数
3
解决办法
5万
查看次数

修复PHP返回JSON

所以基本上我有我的骨干应用程序对我的苗条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数据. …

ajax jquery json slim backbone.js

7
推荐指数
2
解决办法
1万
查看次数

标签 统计

ajax ×1

backbone.js ×1

express ×1

jquery ×1

json ×1

node.js ×1

slim ×1