B
B
bahek24627742014-04-12 16:58:57
PHP
bahek2462774, 2014-04-12 16:58:57

$.getJSON doesn't work but $.get does?

Help solve the problem.
doing so

$.getJSON('http://somedomain.com/mmm?callback=? ')
  .done(function(data) {
    console.log(data);
  })
  .fail(function(jqXHR, status, error) {
    console.log(status, error);
  });

if I change getJSON to get, then in console.log() in the .done() function, the normal data object immediately falls out, which is what is needed. But why doesn't getJSON work? gives an error message
parsererror SyntaxError {stack: (...), message: "Unexpected token :"}


here are the response headers
HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Sat, 12 Apr 2014 13:56:33 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Server: nginx/1.4.5
Transfer-Encoding: chunked
X-Powered-By: PHP/5.6.0alpha1


returns json - php (zendFramework 2)
echo $this->json($this->result, array(
        'enableJsonExprFinder' => true,
    ));

Answer the question

In order to leave comments, you need to log in

3 answer(s)
J
Jonh Doe, 2014-04-12
@bahek2462774

You need to understand the difference between jsonp and json. These are fundamentally different things. Jsonp is how your script will wrap and play. It needs a callback. With jsonp, a script dom element is created in the body of the document into which the response is inserted. Naturally, this element must contain valid js code, with a function. Those. the server should return something like function qwe(){ /* code here */ }. And json is, in fact, a serialized array in some way, which by itself will not be executed in any way.

T
Truth4oll, 2014-04-12
@Truth4oll

yes, the answer is probably not quite valid for json parser

Y
Yuri Morozov, 2014-04-12
@metamorph

And look what comes to jqXHR.responseText.
Maybe there's some bullshit in there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question