how to get image url from ";offset=1&q=cars" api using jquery. i'm unable to do it. bellow i've attached my code
<script src=".2.1/jquery.min.js"></script>
<script>
$.ajax({
url:";offset=1&q=cars",
type:"GET",
crossDomain : true,
async: false,
dataType: "jsonp",
jsonpCallback: "myJsonMethod",
success: function(json) {
$.parseJson(json)
},
error: function(e) {
console.log(e);
}
});
function myJsonMethod(response)
{
console.log(response);
}
</script>
how to get image url from "https://api.qwant./api/search/images?count=10&offset=1&q=cars" api using jquery. i'm unable to do it. bellow i've attached my code
<script src="https://ajax.googleapis./ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$.ajax({
url:"https://api.qwant./api/search/images?count=10&offset=1&q=cars",
type:"GET",
crossDomain : true,
async: false,
dataType: "jsonp",
jsonpCallback: "myJsonMethod",
success: function(json) {
$.parseJson(json)
},
error: function(e) {
console.log(e);
}
});
function myJsonMethod(response)
{
console.log(response);
}
</script>
Share
Improve this question
asked Oct 28, 2017 at 10:35
Abhijit DasAbhijit Das
1052 gold badges3 silver badges6 bronze badges
2 Answers
Reset to default 6Your request isn't working because of CORS, which is enabled on the API server. You need a proxy server to workaround this. For development purposes you could use a free online proxy server, your code then simplifies:
$.ajax({
url:"<PROXY:SERVER>https://api.qwant./api/search/images?count=10&offset=1&q=cars",
success: function(json) {
// Do stuff with data
},
error: function(e) {
console.log(e);
}
});
As an example check out this working fiddle.
Try this
$.ajax({
url:"https://api.qwant./api/search/images?count=10&offset=1&q=cars",
type:"GET",
crossDomain : true,
async: false,
contentType: "application/json; charset=utf-8",
dataType: "json",
jsonpCallback: "myJsonMethod",
success: function(json) {
$.parseJson(json)
},
error: function(e) {
console.log(e);
}
});
This is a CORS thing, so you can server all this up from a web server, like http-server, and I think certain browsers like Firefox allow this to occur locally.
There are some flags with Chrome that'd allow it to work locally like this too, I believe.
Cheers
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743726466a4496700.html
评论列表(0条)