2

I have a request being made to the Steam WebAPI via Jquery:

$.ajax({
   url: myurl,
   dataType: 'json', 
   success: success,
   cache: true
});

And this is the response I get from the Steam Community servers (truncated):

{
"result": {
    "status": 1,
    "num_results": 25,
    "total_results": 500,
    "results_remaining": 475,
    "matches": [
        [[OMMITTED FOR BREVITY]]

But Chrome is giving me this error (and doesn't run the success function):

Uncaught SyntaxError: Unexpected token :  

(This error is for line 2 - "result": { )

Am I missing something?

18
  • 1
    It looks like you're calling something that isn't actually JSONP. Commented Nov 13, 2013 at 1:11
  • 1
    It's not JSONP, it's just normal JSON. Why would that make this result in failure? Commented Nov 13, 2013 at 1:16
  • success is the function that gets when the request gets completed successfully. If it makes any difference, the success function is dynamically assigned (this is all inside a function). Commented Nov 13, 2013 at 1:25
  • 1
    What is the result if you paste the resulting text into JSONLint? Commented Nov 13, 2013 at 1:26
  • 1
    are both ressources placed on the same domain/port? Commented Nov 13, 2013 at 1:31

1 Answer 1

1

The requested URL(taken from the comments) contains this part: json=jQuery110205507024014368653_1384305203368

This obviously is a result of a different request with the settings:

   dataType: "jsonp", 
   jsonp: "json" 

(jQuery wouldn't add this parameter independently without these settings)

In this case the expected response-format is jsonp(not json) , but the response is json( what results in the error).

Sign up to request clarification or add additional context in comments.

3 Comments

It's not the result of a different request. The code I put in the question is the code that is being used. That's why I can't get to the bottom of this issue. It returns JSON data but it still gives me the bad syntax error.
As I said, jQuery wouldn't add this parameter independently without these settings . However, it's not possible for me to request the ressource directly to inspect the headers, assuming there will no Access-Control-Allow-Origin-header be sent that matches your domain you will not be able to access the JSON at all, JSONP would be the only option in this case.
This 'Access-Control-Allow-Origin' piece is the reason the syntax is the way it is. I have no idea what this actually means, but if I do it another way it gives me this error. Can you just briefly elaborate on what this is?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.