Reputation: 684
I'm having a data in my view such as
<input name="start" type="hidden" value="1" />
<input name="end" type="hidden" value="2" />
I need to pass this values to the controller when my page getting load.
How should I pass it to the controller.
Is there any way to send this values using jQuery!!!...
Someone help me..
Upvotes: 2
Views: 1271
Reputation: 3039
Why don't you try ajax
?
<input name="start" class="start" type="hidden" value="some_value1" />
<input name="end" class="end" type="hidden" value="some_value2" />
var postData = {
"param1" : some_value1,
"param2" : some_value2
};
console.log(postData);
$.ajax({
type: "POST",
url: "test.php",
data: postData,
success: function(){
alert(param1 + ' ' + param2);
window.open("test.php");
}
});
test.php
is your controller...
Upvotes: 2
Reputation: 693
Try this
<input name="start" class="start" type="hidden" value="1" />
<input name="end" class="end" type="hidden" value="2" />
<script type="text/javascript">
$(function() {
pass_value();
});
function pass_value(){
var start = $(".start").val();
var end = $(".end").val();
$.post('{your_url}', {start:start, end:end},function(data){
console.log(data);
})
}
</script>
Upvotes: 1