POsting the forms data with JQuery Form Plugin to cakephp controller

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;

}

}

Answers


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.


Need Your Help

Socket programming - C - choosing connection

c sockets select network-programming webserver

I am trying to do a web server that will provide a set of questions (poll) to the users trying to connect to it.

MVC3 Razor - Models and Views

asp.net-mvc-3 razor model views partial

I have an action that creates a List and returns it to my view..