[英]How to pass variables to MVC using jquery and ajax
I am using CodeIgniter, and I am trying to pass my variable in jquery to my controller and then pass it back to my view. 我正在使用CodeIgniter,并且尝试将jquery中的变量传递给控制器,然后将其传递回视图。 ( When I do an
alert(dateclicked);
before the ajax, the right value is shows in the alert. ) (当我执行
alert(dateclicked);
在ajax之前,警报中会显示正确的值。)
View 视图
<head>
< script type = "text/javascript" >
$(document).ready(function() {
$('.test').click(function() {
var test = $(this).('.val').html();
$ajax({
type: 'POST',
data: {
val: val
},
url: '<?php echo site_url('test');?>',
success: function(result) {
alert(test);
}
});
});
});
< /script>
Its not 不是
$ajax({
its 它的
$.ajax({
^
This should be 这应该是
success: function(result) {
alert(result); <--- result not dateclicked.
}
EDIT 编辑
$('.link').click(function(event) {
event.preventDefault();
// ajax here
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.