1
votes

I am trying to run this code in my browser's console:

$.ajax({
    dataType: 'json',
    url: 'http://www.web2pdfconvert.com/engine?curl=http://www.nytimes.com&outputmode=json?callback=?',
    success: function (data) {
    if(data.resultcode == 1) {
      console.log(true);
    } else {
      console.log(false);
    }

  },
  });

However, I am getting a Cross Domain Request Error. when I try to make a simple JSON request then also same error occurs, because JSON request cannot be made on Cross Domains. however, when you go to this URL:

http://www.web2pdfconvert.com/engine?curl=http://www.nytimes.com&outputmode=json

You'll be able to see the JSON data. However, a key point written in the documentation of this websites API says that:

json - all conversion data are returned as JSON object. Also JSONP cross domain communication supported usign jQuery.

Thanks in advance.

1
web2pdfconvert.com/engine?curl=http://…? The url you're using isn't JSON format? Or am I missing something?user996559
The JSON is returned by this URL web2pdfconvert.com/engine?curl=http://…Apoorv Saxena

1 Answers

2
votes

Use jsonp instead:

$.ajax({
    dataType: 'jsonp',
    url: 'http://www.web2pdfconvert.com/engine?curl=http://www.nytimes.com&outputmode=json',
     jsonp: "callback",
     success: function (data) {
    if(data.resultcode == 1) {
      console.log(true);
   } else {
      console.log(false);
    }

  },
  });