I have the following problem: I'm trying to develop an App, with Nodejs + cassandra, but inside a form that I have, when calling an ajax method which is inside the same form (.jade) it gives me an error here is the code:
script.
function ajaxejecutar() {
'use strict';
var agencia = document.addagencyform.nombagency.value;
$.ajax({
contentType: "application/json; charset=UTF-8",
datatype: "JSON",
data: {agencia:agencia},
url: "/runnerapp/querylib/queryagency",
async: true,
beforeSend: function () {
$('#nombagency').val('Buscando...');
},
success: function (res) {
console.log(resp);
console.log(' Agencia existe');
},
error: function (jqXHR, status, error) {
console.log(' error en el metodo AJAX');
console.log(' estado del error: ' + JSON.stringify(status));
console.log(' valor del error: ' + error);
console.log(' valor jqXHR: ' + JSON.stringify(jqXHR));
console.log(' valor de la agencia: ' + agencia);
},
timeout: 10000
})
}
and this is the .js file that should be processed:
'use strict';
var cassandra = require('cassandra-driver'),
express = require('express'),
router = express.Router(),
agencia = document.getElementById('nombagency').value,
client = new cassandra.Client({contactPoints:['127.0.0.1']});
client.connect(function (err, result) {
if (err) {
console.log('error al conectarse en consulta ajax: '+err);
} else {
console.log('conectado a consulta jquery...'+result);
}
});
var getdetails ='SELECT * FROM runnerks.agency WHERE nombagency = ?';
router.get('/dashboard/addagency', function(req, res, next) {
client.execute(getdetails, [req.params.nombagency], function(err, result)
{
if (err) {
res.status(404).send({msg: err});
console.log('error en consulta...');
} else {
console.log('la agencia existe: '+result);
}
});
});
module.exports = router;
If someone could help me I would greatly appreciate it.
Note: I send to print with a console.log and I always get the same error: GET / runner / querylib / queryagency? Agency = Agency ABC 500 80.242 ms - 1149