JSON cut when sending by post with AJAX

4

I'm using Angular to make a database entry, I get the data from my inputs I put into an object and I transform it into a JSON and I send it by post, but it happens that my JSON is cut and I do not do the minimum idea of why.

 var meuJson = angular.toJson(meuObjeto);
 $http({
   method: 'POST',
   url: 'http://url/arquivo.php',
   data: {
     'data': meuJson
   }
 })
 .success(function (data){
    console.log(data);
  })

My JSON is appearing like this.

[
  {
    "uuid":"56456456456456456456465456"
  },
  {
    "store_name":"",
    "store_email":"",
    "store_facebook":"",
    "contact_name":"Juca",
    "contact_email":"[email protected]",
    "contact_facebook":"http://localho

I gave a console.log() to Json when I get it and show it, then I show the answer, see the image that is better understood:

    
asked by anonymous 04.04.2014 / 19:08

1 answer

2

I still do not have permissions to comment, so I'll post an alternative anyway: well, I've had similar problems with cut transfers, and one of the main problems in this case is character encoding. For some reason I do not know, when the encoding of the submitted text is different from the encoding expected by the server in certain cases it cuts the string from a character it can not interpret - I think.

To check the encoding of the text being sent, use the mb_detect_encoding . If the received JSON encoding is different than expected try to force the conversion by PHP, or by setting the charset of the page that is sending JSON.

Converting to PHP:

$charset = mb_detect_encoding($_POST['data']);
$json = mb_convert_encoding($_POST['data'], "UTF-8", $encoding);

Converting to HTML: link

    
08.04.2014 / 13:36