2013-07-31 14 views
5

Sto utilizzando un servizio per aggiornare una tabella DB.

myApp.factory('createGal', function ($http, $q) 
{ 
    return { 
     createGal: function() 
     { 
      var deferred = $q.defer(); 
      var newGalleryArray = {}; 

      newGalleryArray.galleryName = 'New Image Gallery'; 
      newGalleryArray.client  = 245; 

      $http.post('/beta/images/create', {newGalleryArray: newGalleryArray}).success(function(data) 
      { 
       console.log(data); 
       deferred.resolve(data); 
      }); 

      return deferred.promise; 
     } 
    }; 
}); 

PHP

public function create() 
{ 
    print_r($_POST); 
} 

L'array sta tornando vuoto. Sto passando l'array in modo errato?

Chrome Dev enter image description here

Grazie

+0

Qual è la console che dice della richiesta? – tymeJV

+0

riuscito, richiesta. Restituisce l'azione DB, solo l'array non viene inviato in POST – Bungdaddy

+0

Interessante ... che cosa sta inviando il tuo PHP indietro? – tymeJV

risposta

6

E 'stato un po' che ho usato PHP, ma non solo $_POST contenente anche la richiesta paramaters? $http.post invia i dati attraverso un payload JSON, non richiede parametri. Quindi, dovrai usare qualcosa come json_decode

+0

DOH !! Ho appena dovuto aggiungere $ json = json_decode (file_get_contents ("php: // input")); – Bungdaddy

+0

Se jQuery sul lato invia i dati del tuo post tramite $ .params e aggiungi Content-Type 'application/x-www-form-urlencoded' all'intestazione della richiesta. In questo modo puoi semplicemente usare $ _POST globale. – Oliver

Problemi correlati