I had that issue with the weather App and ended up using this URL proxy service - https://crossorigin.me/
But no matter what I do I can't make this one work. I even tried copying in code from tutorials (forgive me) just too see if I as going mad but it was still throwing the same error
Dylan
@dhcodes
@WilliamFace i just used that prepend and it did work
change your success function to console.log(request)
and you will see an XML return in the console
@WilliamFace fwiw, I find that jquery.getJSON is an easier approach for apis or AJAX even may be easier than XML
but that could be because I don't know how to parse XML
if you want, I can fork your project
and send a link
Will Kempster
@kempsterrrr
If you could, I'd be really grateful
Just added the s to http and appended with https://crossorigin.me and the error has gone but the API is still not being called and not adding the response text to searchObj
@dhcodes maybe I am just trying to be too clever no using get.JSON! I did the weather app with it and then re-wrote it for practice with vanilla js, thought I could go ahead and do this one in vanilla but obviosuly not :smile:
@dhcodes thanks!! Finally it's called the API :smile: for someone reason though it wont parse the responseText to JSON when using JSON.prase(request.responseText)
CamperBot
@camperbot
williamface sends brownie points to @dhcodes :sparkles: :thumbsup: :sparkles:
Which is really weird as the information is clearly there in responseText
Dylan
@dhcodes
@WilliamFace i think it's because your response is coming back as xml and not json
Will Kempster
@kempsterrrr
@dhcodes ahhhhhhh that makes sense ! The error it is throwing up now is 'unexpected / at position blah blah' which must be the / at the start of the XML
_
Dylan
@dhcodes
yeah, i'm not sure there's a good way to convert it from xml though
idk why it isn't giving json since you request that in the format
Will Kempster
@kempsterrrr
yeah it's really weird, I actually think it is returning JSON but /**/( is appended to the start of the file so you can't use JSON.parse
never seen that before
Just tried it on my weather app and the /**/( is not there
Stephen James
@sjames1958gm
@WilliamFace Can you save your codepen page, I'd like to take a look at the latest.
Dylan
@dhcodes
@WilliamFace yeah but if you console.log(request.responseText) it is definitely xml
@leena-d you have set the background-color to black
Stephen James
@sjames1958gm
@WilliamFace Since you are using that proxy URL - remove callback=? and change format back to json.
Dylan
@dhcodes
do you mean the hover states @leena-d
Will Kempster
@kempsterrrr
@sjames1958gm YES!
Stephen James
@sjames1958gm
@WilliamFace - console.log(searchObj.response);
Dylan
@dhcodes
@sjames1958gm do you know what was causing that?
i'm curious
Will Kempster
@kempsterrrr
me too
oddly it still wont parse to a JSON object.... searchObj = JSON.parse(request.responseText); is still not working
Stephen James
@sjames1958gm
When I entered that URL without the crossorigin proxy into my browser it was giving back html page. when i changed it back to json it appeared the response was the JSONP callback code /**/ - I am not sure but the jsonp I have seen starts with /**/ but not sure.
@WilliamFaceJSON.parse(request.response)
Will Kempster
@kempsterrrr
I think the format in the URL was wrong so it was reverting back to it's default
@sjames1958gm that parse worked, thanks.
CamperBot
@camperbot
williamface sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles: