Saturday 15 September 2012

node.js - Blocking requests coming from host A to host B nodejs -



node.js - Blocking requests coming from host A to host B nodejs -

my nodejs httpserver (i'm not using express) hosted in host a, domain: www.host-a.com , this:

dispatcher.addlistener("post", "/admin/insert_data", function(req, res) { var body=''; req.on('data', function(chunk) { body += chunk.tostring(); }); req.on('end', function() { var parsedbody = require('querystring').parse(body); mongoclient.connect('mongodb://localhost:27017/database1', function(err, db) { if (err) { res.writehead(500) ; homecoming res.end('database offline') ; } console.log("connected correctly server"); var col = db.collection('mycollection'); col.insert(parsedbody, function() { db.close(); var json = json.stringify({status: "0"}); res.writehead(200, { 'content-type': 'application/json' }); res.end(json); }); }); }); });

the client side following:

$("form[name='manage_notizie']").submit(function(e) { req="../admin/insert_data" var tmp_notizia = $( "input[name=notizia]" ).val(); var tmp_id_notizia = $( "input[name=id_notizia]" ).val(); $.ajax({ url: req, type: "post", data: {id_notizia:tmp_id_notizia, notizia:tmp_notizia}, async: false, success: function (msg) { location.reload(); }, error: function (msg) { alert("errore nel server") }, cache: false, }); e.preventdefault(); });

i know deafult, if don't specify access command allow origin, server respond if request arrives (host a).

now, illustration if request comes www.host-b.com www.host-a.com/insert_data, server not reply request (like want) computing stuffs (which don't want)

am missing something?

node.js cors

No comments:

Post a Comment