1

First of all , I know how jsonp works. it injecting js code as callback ({a:1}) from a server who supports these kind of requests.

I have this code which connects to facebook , and they return an invalid json result.

they do support jsonp cause using jquery ajax with datatype:jsonp - DOES return value ( invalid one though)

the response from jsonp call is :

for(;;);  //<----------- the problem
{
    "__ar": 1,
    "error": 1357001,
    "errorSummary": "Not Logged In",
    "errorDescription": "Please log in to continue.",
    "payload": {
        "__dialog": {
            "title": {
                "__html": "Not Logged In"
            },
            "body": {
                "__html": "Please log in to continue."
            },
            "buttons": [
            {
                "name": "login",
                "label": "Log In",
                "handler": "goURI(\"\/login.php\", true);"
            }],
            "modal": true,
            "onloadRegister": ["setInterval(function () {\n        if (getCookie(\"c_user\") || getCookie(\"csm\")) {\n          window.location.reload();\n        }}, 5000);"]
        }
    },
    "js": ["8fTQS"],
    "resource_map": {
        "8fTQS": {
            "type": "js",
            "src": "https:\/\/s-static.ak.fbcdn.net\/rsrc.php\/v2\/y9\/r\/NXhpMFxH7x0.js"
        }
    }
}

Of course- this is an invalid json.

Firebug : enter image description here

When I paste this text to jsonlint , and remove the first line - it is a valid json.

If I could remove the for(;;); line from the result - I could have parse the result.

I want to catch the textual response and replace for(;;); with empty string.

I want to jquery documentation and I noticed this info :

enter image description here

I did try to write jsonp text but still error.

How can I get the result and replace the for(;;); with empty string without showing the error ?

Royi Namir
  • 131,490
  • 121
  • 408
  • 714
  • possible duplicate of [Accessing Facebook servers with cross-domain JSONP and malformed JSON answer](http://stackoverflow.com/questions/4754306/accessing-facebook-servers-with-cross-domain-jsonp-and-malformed-json-answer) –  Aug 02 '12 at 12:39
  • 1
    To me it does not look like this URL is supposed to be accessed from external websites... do you have a link to the documentation? See: http://stackoverflow.com/questions/3146798/why-do-people-put-code-like-throw-1-dont-be-evil-and-for-in-front-of and http://stackoverflow.com/questions/6339790/what-does-a-ajax-call-response-like-for-json-data-mean – Felix Kling Aug 02 '12 at 12:42
  • @Royi: Are you saying the data *is* available as a `"json"` request, and the `for` statement is messing up the parsing? Or are you saying it's *not* available as a `"json"` request, and you're trying to get around the JSONP block? –  Aug 02 '12 at 12:43
  • @amnotiam it can be accessed with jsonp request. but the result is malformed. ( it hard to explain) but the second part of your question in the correct one. – Royi Namir Aug 02 '12 at 12:47
  • @AndreasNiedermair dupliacte...but with no answers. – Royi Namir Aug 02 '12 at 12:49
  • @amnotiam what do you say about the datatype space-separated values , can it help ? – Royi Namir Aug 02 '12 at 12:53
  • @RoyiNamir: No. There can only be one response type. It seems that you're trying to do something that you're not permitted to do. –  Aug 02 '12 at 12:56
  • ...perhaps the server API requires a key in order to remove the `for` statement. –  Aug 02 '12 at 12:57
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14799/discussion-between-royi-namir-and-am-not-i-am) – Royi Namir Aug 02 '12 at 12:59
  • @amnotiam I know there can be only 1 response type. but datatype ( according to jquery) can use the text value... ( see the yellow parts) – Royi Namir Aug 02 '12 at 13:45
  • 2
    @RoyiNamir You do not understand what that means. It means that the **data** of JSONP response can be converted to text/xml/whatever. But it still needs a valid JSONP response. And the one you are receiving is not valid and there's **nothing** you can do about it. It is impossible to parse clean JSONP response, otherwise it wouldn't be called JSONP. :) – freakish Aug 02 '12 at 14:29

0 Answers0