2012-09-23 3 views
0

Je suis nouveau à Jquery. J'essaie de poster un formulaire dans un fichier php en utilisant Jquery Post, j'ai fait un var_dump ($ _ POST) dans le fichier php mais je ne peux voir qu'un tableau vide (vu en utilisant firebug net), mais je reviens au succès fonction de Jquery. Peut-être que je fais quelque chose de stupide .. Tout le comportement Javascript fonctionne comme prévu, sauf ce problème. Quelqu'un s'il vous plaît aiderAjax POST ne fonctionne pas en utilisant Jquery et PHP

$(document).ready(function() { 

    //if submit button is clicked 
    $('#submit').click(function() {  

     //show the loading sign 
     $('#example').modal('show') ; 


     //start the ajax 
     $.ajax({ 
      //this is the php file that processes the data 
      url: "mvc/process_form.php", 

      //GET method is used 
      type: "POST", 


      //Do not cache the page 
      cache: false, 

      //success 
      success: function (html) {    
       //if process_form.php returned 1/true (process success) 

       if (html==1) {     
        //hide the form 
        $('.form').fadeOut('slow');     

        //show the success message 
        $('.done').fadeIn('slow'); 

       //if process.php returned 0/false (send mail failed) 
       } else alert('Sorry, unexpected error. Please try again later.');    
      }  
     }); 

     //cancel the submit button default behaviours 
     return false; 
    }); 
}); 

Répondre

1

Vous devez transmettre des données de formulaire en tant que sérialisation. En ce moment, vous ne transmettez pas de données de formulaire dans votre fonction ajax.

Ici, vous allez:

$(document).ready(function() { 

    //if submit button is clicked 
    $('#submit').click(function() {  

     //show the loading sign 
     $('#example').modal('show') ; 


     //start the ajax 
     $.ajax({ 
      //this is the php file that processes the data 
      url: "mvc/process_form.php", 

      //GET method is used 
      type: "POST", 
      data: $("#testform").serialize(), 

      //Do not cache the page 
      cache: false, 

      //success 
      success: function (html) {    
       //if process_form.php returned 1/true (process success) 

       if (html==1) {     
        //hide the form 
        $('.form').fadeOut('slow');     

        //show the success message 
        $('.done').fadeIn('slow'); 

       //if process.php returned 0/false (send mail failed) 
       } else alert('Sorry, unexpected error. Please try again later.');    
      }  
     }); 

     //cancel the submit button default behaviours 
     return false; 
    }); 
}); 
+0

Merci pour votre temps .. il m'a vraiment aidé – Codemator

+0

votre bienvenue @Renjith – GBD

2

vous n'êtes pas de passage tout _POST data $ dans votre fonction ajax. http://api.jquery.com/jQuery.ajax/

+0

J'ai une trentaine d'entrées dans ma forme Est-ce que vous voulez dire que je dois passer toutes les entrées manuellement aux données ? – Codemator

+0

vous pouvez utiliser la sérialisation de formulaire. – GBD

+0

comme dit @GBD, utilisez la sérialisation. –

0

Essayez cela aussi:

var url = "mvc/process_form.php", 
    data = {hello: hello}; 
$.post(url,data, 
     function (status) 
     { 
     alert(status); 
     } 
);