$.ajax({
url:url,
method:'GET',
dataType:'JSONP'
}).done(function(json){
var author = json.quoteAuthor
var text = json.quoteText
$(".quotes").empty()
$("#quote-author-box").append(author)
$("#quote-text-box").append(author)
})
})
})
I just get back errors saying, Error: wrong method.
Can anyone give me some tips? I am not working with codepen yet, but only with Atom. I assume it will be the same? If not, knowing this would be useful so I don’t solve the COR problem here, only to face an entirely dif one with codepen.
I’ve spend about an hour researching this problem and none of the solutions I’ve come across have worked.
Can U explain the second one though. Where’d you come up with that? I also understand the .ajax but …
I’m annoyed that I couldn’t figure this out. I read all the docs. They just say to add callback=?" and it’s confusing if they mean to add that literally, or to add a callback. What does add a callback even mean in a url?
The .ajax docs are better but very hard to follow, the jsonp section alone I’m referring to here.
I wish I new how it works. I just understand that JSONP is a way to get around the same domain policy and that JSONP wants a callback. I think putting “&callback=?” is either fooling it into thinking that you gave it a callback or is telling it, “Yeah, I know you want a callback but I don’t need one so I’ll give you this dummy so you know that I’m purposely choosing not to give one.”
Here’s some interesting discussion on the topic:
But like I said, I’m still figuring it out myself.
I tried this code as written in CodePen on Chrome, and I got further, in fact, it almost worked. However, I get
Refused to execute script from 'http://api.forismatic.com/api/1.0/?&jsonp=jQuery31104107977640992704_1493006061699&method=getQuote&format=jsonp&key=15723&lang=en&_=1493006061700'
because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
So basically, it looks like I got past the cross-domain problem, only to run into something new. I don’t think there is anything I can do about this other than choose a different random quote API?