Welcome Guest, Not a member yet? Register   Sign In
passing variable from javascript to a controller via link
#7

[eluser]Mushex Antaranian[/eluser]
I you're using js frameworks, it's pretty simple (and with pure js it's not so hard Wink )

In your markup
Code:
<form id="the-form">
<label for="input">Input</label>&lt;input type="text" value="" name="input"/&gt;
<label for="input-2">Second Input</label>&lt;input type="text" value="" name="input-2"/&gt;
&lt;/form&gt;
<a href="#" id="submit-the-form">Submit Form</a>

In js (!this is jQuery code)
Code:
$sumbitLink = $('#submit-the-form')
$submitLink.click(function(){
    $.ajax({
               url: 'url/to/post/',
               type: 'POST',
               // how you'll receive data controller outputs (can set as html, xml, json)
               dataType: 'json',
               data: $('#the-form').serialize(),
               success: function(data){
                            //do something with response
                        }
    }) // close $.ajax
}) //close .click


Messages In This Thread
passing variable from javascript to a controller via link - by El Forum - 05-22-2009, 08:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB