views:

539

answers:

2

Hi, i am using Form plugin of JQuery.. I added the js file of Form plugin.

Already a form is in my code..beforeSubmit alerts the actual form contents correctly,I want to POst this value into my serverside..I tried with the following ,But not working...

My code is

<?php echo $form->create('Result',array('action'=>'submit'));?>
//some input text fields,texarea fields
<?php echo $form->end('submit');?>

 <script>
  $(document).ready(function(){
  var options = { 

    beforeSubmit:  showRequest,  // pre-submit callback 
    success:       showResponse,  // post-submit callback 
     url: "http://localhost/cake_1.2.1.8004/index.php/results/submit1",
    type: 'POST',
    resetForm: true        // reset the form after successful submit 

}; 


$('#ResultSubmit1Form').submit(function() { 

    $(this).ajaxSubmit(options); 


    return false; 
}); 


 });//ready 

    // pre-submit callback 
 function showRequest(formData, jqForm, options) { 

var queryString = $.param(formData); 


alert('About to submit: \n\n' + queryString); 

     $.ajax({
   type: "POST",
  url: "http://localhost/cake_1.2.1.8004/index.php/results/submit1",
  data: "str="+queryString,

 success: function(msg){
  alert( "Data Saved: " + msg);
 }

  }); 


return true; 
} 

   // post-submit callback 
  function showResponse(responseText, statusText)  { 


alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
    '\n\nThe output div should have already been updated with the responseText.'); 
 }

And in my CakePHp controller

<?php
class ResultsController extends AppController

{

  var $name = 'Results';
 var $helpers=array('Html','Ajax','Javascript','Form');
   var $components = array( 'RequestHandler','Email');
  var $uses=array('Form','User','Attribute','Result');
 function submit($id = null)
 {

  $str=$_POST['str'];
echo "POSTED value ".$str;

}

}

+1  A: 

Try using a relative URL for the URL parameter:

 url: "/cake_1.2.1.8004/index.php/results/submit",

Would also be a good idea to echo out some text on the server side just to make sure it's not server output that is failing.

EDIT: I can see you're doing that already, sorry didn't notice it.

karim79
Aruna
A: 

Aruna, did you ever figure this out? I am having very similar problems right now. I can send my data via GET just fine, but if I POST my data, it never shows up serverside in CakePHP's $this->params['form'] structure. Also, if I check $this->RequestHandler->isPost() it's false, but $this->RequestHandler-.isGet() is true, even though Firebug shows me quite clearly that I am POSTing my data exactly as I think I should. Very frustrating!

haigek