Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/11/2014, 05:12
Samka
 
Fecha de Ingreso: mayo-2011
Ubicación: Entre Navarra y Aragón
Mensajes: 96
Antigüedad: 13 años
Puntos: 0
problema con servicio REST

estoy tratando de introducir datos por POST en mi base de datos y me dice que los datos son undefined y me da un parsererror, sin embargo si en la base de datos permito el NULL, introduce un registro pero con NULL... no encuentro el posible error

además si compruebo el contenido de la variable Task que es la que contiene el JSON, el resultado está bien introducido y validado...

aquí el codigo javascript

Código Javascript:
Ver original
  1. var API_URI = "http://localhost/prueba";
  2.     function clearForm() {
  3.         $("#form-prueba input:first-child").val("");
  4.     }
  5.     function taskNameIsEmpty() {
  6.         return ($("#form-prueba input:first-child").val().length == 0);
  7.     }
  8.     function getTaskJSON() {
  9.         return JSON.stringify({
  10.             nombre: getpruebaName()
  11.         });
  12.     }
  13.     function getTaskName() {
  14.         return $("#form-prueba input:first-child").val();
  15.     }
  16.    
  17.     $("#form-prueba input:last-child").on("click", function createTask(task) {
  18.         if (taskNameIsEmpty()){
  19.             alert("Oops! Completa el formulario!");
  20.         }else{
  21.             // 1.2 JSON.Stringify
  22.             var task = getTaskJSON();
  23.         };
  24.         alert(task)
  25.         $.ajax({
  26.             type:'POST',
  27.             contentType:'application/json',
  28.             url:API_URI,
  29.             dataType:"json",
  30.             data:task,     
  31.             success:function(response, task) {
  32.                 clearForm();
  33.             },    
  34.             error:function(jqXHR, data, textStatus, errorThrown) {
  35.                 console.log(data);
  36.                 console.log(errorThrown);
  37.             }
  38.         });
  39.     });