I am fairly new to Node JS so may be I am asking a too broad/poor question, but pardon me for it. I have been trying to call a nodejs function through AJAX Jquery and then want to show data returned from nodejs on my view but I am always ending up in error block. This is my code, if anyone could guide me through this?
index.jade(Client)
extends layout
block content
body
head
script(src=' https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js')
h1= title
p Welcome to #{title}
a(href='' onClick="myFunction1()") Test
script.
var myFunction1=function(){
var url = './checkUser1';
var message = {userName: "XYZ"};
var dataType = 'application/json';
$.ajax({
url: './checkUser1',
data: '{"data": "TEST"}',
type: 'GET',
dataType: dataType,
success: function (data) {
var ret = jQuery.parseJSON(data);
console.log('Success: '+ret)
},
error: function (xhr, status, error) {
console.log('Error: ' + error.message);
},
});
}
index.js
router.get('/checkUser1', function(req, res) {
res.send({'data': 'some data is coming up'});
});
Now what I want is once I get response from this function I want to print a alertbox dispplaying this data
{'data': 'some data is coming up'}
Any idea what wrong I am doing?