weixin_33694172 2015-05-17 19:01 采纳率: 0%
浏览 195

AJAX错误:连接被拒绝?

I'm running a Digital Ocean server here on a MEN stack (MongoDB, Express, and Node), with a registration form: http://45.55.177.167:3000/register

If you try to select an option from the dropdown, I'm getting the following error: GET http://45.55.177.167:3000/price?name=pro&cycle=monthly net::ERR_CONNECTION_REFUSED

I'm wondering why this is? I would like for the error to go away and get the response back so that the price changes accordingly.

My AJAX method:

$.get('/price', parameters, function(data) {
    callback(data.price);
});

The Route: app.route('/price').get(plans.getPrice);

The Controller:

var param_name = req.query.name;
var param_cycle = req.query.cycle;

var query = param_name + "_" + param_cycle;

Plan.findByName(query, function(err, selected_plan) {
    var formatted_price = format_price(selected_plan.price) + '.00';
    res.send({price: formatted_price});
});

This is working fine on my localhost, but when I deploy it to a droplet, I'm getting the error. Please let me know if clarification is needed.

  • 写回答

1条回答 默认 最新

  • weixin_33738578 2015-05-19 03:19
    关注

    After checking your ip, I determined that your problem was data. You were getting the error "refused connection" because the app didn't have any sanity tests on the expected object parameters it was operating on. Without data, trying to access properties that were undefined was throwing errors, causing your app to break without and return the error you saw in the client.

    We didn't change any of your code to resolve this issue. Your project can be considered done.

    Migrating your data from your local mongo db collections to your remote host resolved the issue. As I demonstrated, there is a simple fix for quickly migrating simple data structures over: connect to mongo on the command line, select your database, and find() each of your collections. As you noticed, they are simply JSON objects that can be copy-pasta'd to the new remote destination's insert() statement with minimal modification.

    This isn't an advisable solution for situations with more data than simply structured, limited data in a handful of collections; you'd want to use a programmatic solution such as dumping the db for anything larger than we were working with here.

    评论

报告相同问题?

悬赏问题

  • ¥15 武汉岩海低应变分析软件,导数据库里不显示波形图
  • ¥15 CreateBitmapFromWicBitmap内存释放问题。
  • ¥30 win c++ socket
  • ¥15 CanMv K210开发板实现功能
  • ¥15 C# datagridview 栏位进度
  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题