I am using HTML and trying to get a JSON response from a URL.
I ran in to cross domain issues.
I then tried using a callback function in order to avoid this problem.
When I do so, and the control passes to the function. I see a "Invalid Label" error in firebug and it shows the JSON response that i get back.
When i did some reading i found a few articles which said the invalid label error could occur because the first word of the JSON response is thought of as a Javascript label and it should be wrapped as a string.
However it did not work because firebug throws the error before even it hits the first line of the function. I also tried debugging in chrome and I get the same result.
Any input would be greatly appreciated.
Found something that might help for you here
Quote from there:
The problem occurs because eval is
interpreting the first item in the
JSON string as a JavaScript Label. The
solution is to wrap the JSON string in
parenthesis.
See this link
I'd suggest using jQuery's .json method to retrieve json, because it hides this implementation.
Thanks for the replies.
I tried the changes and still was facing the same issue. THe solution of wrapping the json string in parenthesis does not solve the problem because this issue is faced even before the code hits that portion.
The problem was that the API was not call back enabled. ( Grrr :() I know! But that was the issue. once the API callback was enabled, the code worked like a charm.
Related
After successfully polling an API nine times, this error sprang up. What is it attempting to communicate? Why does it come up after so many good polls? What concrete steps should I take to resolve this?
Thanks for addressing these questions! :)
The argument you are passing to Jason.decode is not valid JSON. In this case it's most likely the response body you got back from the API endpoint. It's likely a string of plain text or HTML, such as:
Internal Server Error
You will need to share your code in order for someone to provide a version of the code that can handle all of the responses you are getting from the API.
https://rapidapi.com/dimas/api/NasaAPI?endpoint=apiendpoint_b4e69440-f966-11e7-809f-87f99bda0814getEarthAssets
I've seen the documentation, which gives "50.37, 26.56" as an example of how to format coordinates. The problem is that when I fill in those coordinates in the linked application, it responds with this:
{
"callback":"error",
"contextWrites":{
"to":{
"status_code":"JSON_VALIDATION",
"status_msg":"Syntax error. Incorrect input JSON. Please, check fields with JSON input."
}
}
}
I have a sneaking suspition that its broken, but if anyone knows how I could get it to work, that would be great. Its also worth mentioning that I've gotten other parts of the same API, such as getPictureOfTheDay, to work, and the ones I've gotten to work don't require arguments.
You need to put a empty json object in the post request.
I dont know why they made it a post request
I was going through some website and stumbled upon following bug in it, while playing with different combinations for url parameters.
When I append ?&=& to any valid url on this website I get following error: /p is part of url (java.lang.ArrayIndexOutOfBoundsException).
Chrome parses the string as below:
But this exception is not raised when I append ?&& instead of ?&=&. Chrome parses both string into same thing.
How is "?&=&" actually parsed and how is it different from "?&&"? As chrome parses them into same thing why does it generate an exception only in former case?
What kind of bug does this website might have?
Can such bug be used to do some kind of attack on this website?
Note:
I do not own this website so I am just curious to know what might have caused this bug.
Issue is seen consistently on both chrome and firefox.
builtwith.com says this website uses ngix server.
Let me know if this is offtopic here. Didnt find any such info.
Edit:
I understand what this exception means. I just want to know if these 2 kind of parameter are parsed differently. What are the possible cause of such a bug.
A java.lang.ArrayOutOfBoundsException caused by the Java backend of the page.
This exception occurs when a java application is trying to access an element in a Java Array that does not exist.
How and why exactly this occurs or how the url parameters are processed is impossible to say without having access to the source code of the backend.
It is not caused by the frontend code or by your browser.
I have a webservice method that if I call directly via url GET returns XML without issue.
However, POST to that same url with Content-Type Json, it fails.
I think I can figure out the issue (I'm guessing it's an encoding or bad character somewhere in there) but I don't know how to debug the problem.
If I set a breakpoint in the webservice, it runs to completion. The failure appears to be happening AFTER the method returns, but BEFORE the json is returned to the caller.
How can I get in between to trace the error?
Please let me know if I can provide more context to help, but I really just need to know how to get in there.
EDIT:
The web service is configured to receive POST and return JSON and in fact DOES correctly return JSON in some cases. However, there are certain calls that are failing, so I need a way to trace this or debug it somehow and figure out why some calls are not working.
The web service is likely not configured to receive POST requests, especially if you are receiving a 405 Method Not Allowed response status.
Although I didn't find a way to debug or intercept the request to find the exact answer, it turns out the problem was the size of the content being returned by the webservice. Following this answer: ASP.NET WebMethod with jQuery json, is there a size limit?
and increasing the json limit fixed the issue!
Is there a way I could have trapped this to find the error without just guessing it was a size limit?
I am trying to contact an API by posting the parameters in the URL. I am unsure whether it will respond in XML or JSON, but it is one of the two, however, it says there is an error.
This is an example of what I'm submitting. I am receiving this in response:
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
I do not know what is going on... I followed the syntax of the POST I believe, my only remaining question about the syntax would be whether the ? is in the right spot. The page API does work when I POST using PHP...
Or maybe it is working, the browser just isn't capable of understanding an XML or JSON response? (I'm using chrome so I do not think this is the issue)
Otherwise, if anyone has any insight on this, I'd be greatful
A different browser yields this error:
XML Parsing Error: syntax error
Location:
Line Number 1, Column 1:Array
^
While the syntax of the URL does seem to be fine, you imply that the API expects the parameters in POST. Adding them to the actual URL means the parameters are passed in GET, rather than POST.
You could try to test this by making a little HTML form containing all the relevant parameters and passing them to this API via POST, and see if that gives you the expected result.
your issue is how their being sent to the api it should be url-encoded
http://api.example.com/api/?apikey=asdfa23462=example&ip=208.74.76.5
should be
http://api.example.com/api/?apikey=asdfa23462&=example&ip=208.74.76.5
also another issue i see is that you have ?apikey=asdfasfsdafsd&=example
the =example could well be the issue all together.
just some thoughts from what i see.