[SOLUCIONADO] Error no llama a funcion jquery was not called parse error

Iniciado por $francisco, Febrero 22, 2016, 02:19:14 AM

Tema anterior - Siguiente tema

0 Miembros y 1 Visitante están viendo este tema.

Febrero 22, 2016, 02:19:14 AM Ultima modificación: Marzo 07, 2016, 12:29:03 PM por blackdrake
Muy buenas a todos, resulta que no puedo obtener respuesta de mi pagina php con ajax.

Código: javascript
$.ajax({
        crossDomain: true,
        url:'http://www.miweb.com/index.php',
        data:{datos:p},
        dataType:'jsonp',
        type:'GET'
    })
    .done(function(data){
        alert(data);
        }
    })
    .fail(function( xhr, status, err){
        alert('error getting scripts: ' + status);
        alert('error getting scripts: ' + err);
        alert('error getting scripts: ' + xhr.responseText);
        alert('error getting scripts: ' + xhr.status);
        alert('error getting scripts: ' + xhr.statusText);
        alert('error getting scripts: ' + JSON.stringify(xhr));
    });


php

Código: php
<?php
header('Content-Type: text/javascript; charset=utf8');
$datos = $_GET['datos'];
//$pagina_inicio = file_get_contents($datos);
//$array = array('response'=>$pagina_inicio);
echo $_GET['callback'].'('.json_encode("{resultado:algo}").');';
?>


El caso es que probando desde mi pc si que funciona, pero con phonegab desde mi mobil no logro hacerlo funcionar.

hola,
con el responseText devuelves el texto de tu consulta, un ejemplo sencillo, supongamos que tu script PHP devuelve esto:

Código: php
    echo "foo|bar";


En Javascript lees el resultado y lo puedes parsear:

Código: php
    var response = ajax.responseText.split('|');



Suerte

Todo resuelta era el servidor el que no me dejaba hacer peticiones jsonp.