Ver Mensaje Individual
  #1 (permalink)  
Antiguo 28/06/2012, 06:24
amelper
 
Fecha de Ingreso: mayo-2012
Ubicación: ISLAS CANARIAS
Mensajes: 5
Antigüedad: 12 años, 4 meses
Puntos: 0
Pregunta Enviar con JQUERY mediante JSONP variables para procesar en un PHP

Hola compañeros!

Mi objetivo es crear dos ficheros, cada uno en un dominio distinto. El primer fichero será un JQuery que extraerá unas variables dadas y posteriormente enviará a un fichero PHP, ubicado en otro dominio, el cual deberá agregar dichas variables en una base de datos.

El fichero PHP está destinado exclusivamente a agregar esos datos al MySQL, por tanto no devolverá nada.

Problema, he conseguido hacerlo con ambos ficheros en el mismo dominio, pero no logro hacerlo como debo.

¿Alguien me puede ayudar?

Thanks!

Código Javascript:
Ver original
  1. function QJ()
  2. {
  3.     //Variables generales
  4.     var IP        = '192.168.56.3';
  5.     var urlclip   = 'http://'+IP+'/almacenar.db.php';
  6.     var divid     = 'UT'+Math.round(Math.random()*100);
  7.  
  8.     //Obtenemos el texto seleccionado
  9.     x = document.createElement('div');
  10.     x.appendChild(window.getSelection().getRangeAt(0).cloneContents());
  11.  
  12.     //Extraemos todo el Tag HEAD
  13.     var head      = document.getElementsByTagName('head')[0];
  14.  
  15.     //Agregamos fichero JQuery
  16.     var jquery    = document.createElement('script');
  17.     jquery.type   = 'text/javascript';
  18.     jquery.src    = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
  19.  
  20.     //Agregamos fichero JQuery-UI (.dialog)
  21.     var jqueryui  = document.createElement('script');
  22.     jqueryui.type = 'text/javascript';
  23.     jqueryui.src  = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.min.js';
  24.  
  25.     head.appendChild(jquery);
  26.     head.appendChild(jqueryui);
  27.  
  28.     jquery.onload = function()
  29.     {
  30.         jqueryui.onload = function()
  31.         {
  32.             $.ajax(
  33.             {
  34.                 url:        urlclip,
  35.                 type:       'post',
  36.                 data:       'q='+escape(x.innerText)+
  37.                             '&u='+location.href+
  38.                             '&t='+escape(document.title)+
  39.                             '&i='+divid,
  40.                 async:      'false',
  41.                 success:function(data)
  42.                 {
  43.                     alert ("enviado");
  44.                 }
  45.             });
  46.         }
  47.     }
  48. }
Código PHP:
Ver original
  1. <?php
  2.     header('Access-Control-Allow-Origin: *');
  3.  
  4.     $DB['host'] = "localhost";
  5.     $DB['user'] = "root";
  6.     $DB['pass'] = "";
  7.     $DB['name'] = "temporal";
  8.  
  9.     $dba = mysql_connect ($DB['host'], $DB['user'], $DB['pass']) or die ("ERROR MYSQL_CONNECT: ". MYSQL_ERROR());
  10.     mysql_select_db($DB['name'],$dba) or die ("ERROR MYSQL_SELECT_DB". MYSQL_ERROR());
  11.  
  12.     $sql = "INSERT INTO JS_Temp VALUES ('".$_POST['i']."','".$_POST['t']."','".$_POST['u']."','".$_POST['q']."');";
  13.     mysql_query ($sql,$dba) or die ("ERROR MYSQL_QUERY<br>$sql<br>".MYSQL_ERROR());
  14.  
  15.     mysql_close ($dba) or die ("ERROR MYSQL_CLOSE: ".MYSQL_ERROR());
  16. ?>