Problems accessing PHP page via Ajax

2

I'm having trouble accessing a PHP page via ajax. When I am trying to access in the access.log it gives the following error:

  

"POST /eglise/mobile/MOB_Acao.php HTTP / 1.1" 200 84 "-" "Mozilla / 5.0   (Linux; Android 4.4.2; XT920 Build / 3_190_2009) AppleWebKit / 537.36   (KHTML, like Gecko) Version / 4.0 Chrome / 30.0.0.0 Mobile Safari / 537.36 "

In ajax I'm doing this:

 jQuery.ajax({
        type: "POST",
        url: w_servidor+"/MOB_Acao.php",
        data: dados,
        success: function( data )
        {
            var e = $.parseJSON(data);
            console.log(e.codError == 506);
        }
 });

My w_server variable is var w_servidor = "http://meuip:8080/eglise/mobile";

I searched on htaccess but it's nothing to do with what's happening. The project is mobile , and what makes us more interesting is that mobile works perfectly.

This request I am specifically making an inquiry, the page that receives the request is written like this:

<?php

include "MOB_PessoasBanco_class.php";
$acao = $_POST['acao'];
error_log($acao);
if ($acao == 'verificar') {
    $actionExecute = new PessoasBanco($_POST, 'verificar');
    echo $actionExecute->verificarPessoas();
}

if ($acao == 'cadastrar') {
    $actionExecute = new PessoasBanco($_POST, 'cadastrar');
    echo $actionExecute->cadastrarPessoa();
}

The page I call below searches the database as follows:

$data = $this->conexao->fetchNaoRestritivo($sql, $dataInput);

But the problem is not in this part, because when I open IntelXDK it works perfectly, and I even did another project to test this connection and everything worked. So the problem is in my code, or in another part of the project.

    
asked by anonymous 08.06.2016 / 19:18

1 answer

1

This information in the access log says that the request returned status 200 (Ok). It is not a mistake. The problem, as Ivan said, is that with $.ajax() you should not use $.parseJSON() . You need to specify the return type in the dataType parameter of Ajax.

It would look like this:

 $.ajax({
            type: "post",
            url: w_servidor+"/MOB_Acao.php",
            data: dados,
            dataType: "json",
            success: function( data )
            {
                // Data é o Array correspondente ao JSON retornado pelo webservice.

                //Você pode dar um console.log(data) para ver a estrutura do Array
            }
     });

Oh, if it is not, monitor the sending of the request in the console, see if it will return the same status 200. If it does not return, comment the returned code here.

    
30.12.2016 / 15:43