0

I want the response from below URL using ajax/getjson method. http://randomvin.com/getAjax.php?qry=random&str=random&fake=false but the problem is javascript is not letting me communicate to above URL as this is not producing JSON. I have tried dataType: 'jsonp' but no luck. It is showing me

SyntaxError: expected expression, got '<'

1FMZU84PXYZA75146

I know that why it is showing me above error because response is not in json but in HTML! There has to be another way, please suggest. Thanks in advance.

SteveFerg
  • 3,466
  • 7
  • 19
  • 31
Amit Naik
  • 43
  • 8
  • I checked above url but it display only a unique ID and no error on console/ – Bugfixer Jul 17 '15 at 05:28
  • http://stackoverflow.com/questions/15005500/loading-cross-domain-html-page-with-jquery-ajax – Strelok Jul 17 '15 at 05:28
  • The response is a HTML, json or jsonp will not help, either change the response from the server to json or handle it as html string and then parse the response. If its a cross domain request, then php curl method to get the response, and make an ajax call to your php script which is making the curl request. – Abhishek Prakash Jul 17 '15 at 05:28

1 Answers1

0

With JSONP, you can only read JSON responses. The webpage you linked to, gives HTML response, but not JSON response. If you have access to that server, then you can modify that response to:

{"result": "1FMCU0GX0DUB94477"}

and then use it with JSONP:

$.getJSON('http://randomvin.com/getAjax.php?qry=random&str=random&fake=false', function (data) {
    console.log(data.result);
});

But if you want to read HTML response from another domain, then the only way is to write your own server side script which sends a GET request to that url and return the data, and call that server side script through AJAX.

Ananth
  • 4,227
  • 2
  • 20
  • 26