2012-11-02 5 views
1

JFormer를 사용하여 양식을 만들고 json_encode ($ formValues)를 사용하여 데이터를 볼 수 있지만 서버의 $ formValues를 캡처 할 수 없습니다.jquery 양식 데이터 캡처

var fvalue = <?php json_encode($formValues) ?>; 
    var ftarget = "http://home.server.com/regcreate.php?data="; 
    var a = document.createElement("script"); 
    a.type = "text/javascript"; 
    a.src = ftarget + fvalue; 
    document.body.appendChild(a); 

값이 단순하면이 방법이 유용합니다. json_encode ($ formValues)를 보내려고해도 작동하지 않습니다. 아무것도 보내지 않았습니다. 내가 올바른 방향으로가는거야? json_encode 대신 jquery serialize 함수를 사용할 수 있습니까?

답변

1

안녕하세요 당신이 Jquery를 사용하는 경우 양식을 직렬화하고 ajax 양식 POST를 사용하여 제출할 수 있습니다. PHP가 객체를 직렬화하는 것이 아니므로 정상적인 $ _POST 형태의 값에 액세스 할 수 있습니다.

$('#btnId').click(function() {  

    $.ajax({ 
     //this is the php file that processes the data and send mail 
     url: "regcreate.php", 

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

     data: $("#Form").serialize(), 
     //Do not cache the page 
     cache: false, 

     //success 
     success: function (html) {    
      //assuming that pgp page returns value boolean value 
      if (html=='1') {     
       //add success message 
      } else alert('Sorry, unexpected error. Please try again later.');    
     }  
    }); 
});