javascript - Obtaining json from api with jquery ajax not working -
i'm trying obtain json object api endpoint using jquery , ajax. code:
$.ajax({ url: 'https://this-specific-website.com/customers.json', type: 'get', contenttype: 'application/json' }).done((response)=> { console.log('helllllo inside response') console.log('response', response) })
i tried same $.getjson this:
$.getjson('https://this-specific-website.com/customers.json', (response)=> { console.log('hello inside response') console.log('response', response) })
but keep getting following error:
no 'access-control-allow-origin' header present on requested resource. origin 'null' therefore not allowed access.
is there way fix issue?
thank in advance!!
update:
i did work. instead of using jquery , ajax on front end, created seperate .js file , used http.get() this:
use jsonp in case server supports this, below sample. alternative call servelet or php in same domain backend call , return response normal ajax (or ajax json_p)
$.ajax({ url:"testserver.php", datatype: 'jsonp', // notice! jsonp <-- p (lowercase) success:function(json){ // stuff json (in case array) alert("success"); }, error:function(){ alert("error"); } });
Comments
Post a Comment