0

Here is my jQuery which works fine on the browser the only issue is it's not going inside success method, but he I check web developer toolbar Network tab its show status:200 OK.

$.ajax({
 url: srpApp.AppURL + "/api/samplerequests",
 dataType: 'jsonp',
 type: "GET",
 success: function(data) {
    alert('sucess');
});

Below is Nodejs app code which using MongoDB, mongoose, express

app.get("/api/samplerequests", function(req, res) {
  db.collection(CONTACTS_COLLECTION).find({}).toArray(function(err, docs) {
    if (err) {
      handleError(res, err.message, "Failed to get contacts.");
    } else {
      res.status(200).json(docs);
    }
  });
});

Tried dataType:'JSON' and text both not worked. I hope the issue with node response

Santosh Kori
  • 461
  • 4
  • 12

1 Answers1

0

After try and error got fix by adding jsonp: 'callback' in ajax and in nodejs added res.jsonp(docs)

Santosh Kori
  • 461
  • 4
  • 12