javascript - jquery ajax "SyntaxError: Unexpected end of input" on valid JSON -


the json returned php is:

{"success":0,"message":"error: no entityid passed!"}

still javascript tells me "syntaxerror: unexpected end of input".

php:

    ...      //check if image id passed removal in post data     if ( isset($_post["entityid"])) {         $entityid = $_post["entityid"];     }     else {         //setup response json         $resp = array();         $resp['success'] = 0;         $resp['message'] = "error: no entityid passed!";          header('content-type: application/json');         echo json_encode($resp);     }      ... 

js:

             // send xhr request              $.ajax({                  datatype: 'json',                  type: $theform.attr('method'),                  url: $theform.attr('action'),                  data: $theform.serialize(),                  success: function(data) {                      //backend returns json variable success either true or false.                      resp = data;                      if(resp.success == 1) {                         //render gallery anew                      }                      else {                         console.log(data);                         if (data.message) {                             $(self).find('.vanillagallery-overlaycontentwrapper').html(data.message);                                }                         else {                             $(self).find('.vanillagallery-overlaycontentwrapper').html('oops! något gick fel, felmeddelande saknas dock.');                                }                      }                   },                  error: function(xhr, status, text) {                      $(self).find('.vanillagallery-overlaycontentwrapper').html('oops! något gick fel...<br />'+text);                  }              }); 

very strange. headers different depending on if request made through ajax or plain separate request directly in browser (not through ajax):

the headers through ajax:

connection:keep-alive content-length:0 content-type:text/html date:wed, 01 apr 2015 17:48:26 gmt keep-alive:timeout=5, max=97 server:apache/2.2.25 (unix) mod_ssl/2.2.25 openssl/0.9.8zc dav/2 php/5.5.3 x-pad:avoid browser bug x-powered-by:php/5.5.3 

and through directly browser adress bar:

connection:keep-alive content-length:52 content-type:application/json date:wed, 01 apr 2015 17:42:23 gmt keep-alive:timeout=5, max=100 server:apache/2.2.25 (unix) mod_ssl/2.2.25 openssl/0.9.8zc dav/2 php/5.5.3 x-powered-by:php/5.5.3 

ok, obvious once @ fresh eyes... in ajax request entityid passed (not obvious sample code since form data isn't displayed...) , first if condition in php code above evaluates true. , in clause, there no output, no echo of sort. that's why "unexpected end of input".

and testing running directly in browser adress bar, way php of course land in else-bracket of php code above, , give response since there no post-data @ doing way...

sorry taking time, 1 tired...


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -