0

我需要在单击复选框时将其发送到远程 url 以调用 Codeigniter 中的控制器这就是我想要做的......

$("#checkbox").click(function() {
   if($("#checkbox").is(':checked')) { 
           alert("go to url"); 
   } else { 
      alert("isnt active"); 
   } 
});
4

2 回答 2

2

使用 ajax 向服务器发出请求。

$.ajax({
  url: "http://example.com/controller-name/function-name/parameter1",
  cache: false
}).done(function(data) {
  //Do something with the response.
});

见:http ://api.jquery.com/jQuery.ajax/

于 2013-06-24T20:21:09.207 回答
1

你可以试试这个

$("#checkbox").click(function() {
    if($("#checkbox").is(':checked')) { 
       $.ajax({
        url:base_url+'your_controller_name/your_function_name',
        type: 'post',
        data:{any data you want to sent},
        success : function(resp){
            if(resp)
            {
                //do what you want
            }
        },
        error : function(resp){}
       }); 
    } else { 
       alert("isnt active"); 
    } 
});

如果您遇到任何问题,请告诉我。

更新

可能你想要这样。

$("#checkbox").click(function(){
    if($("#checkbox").is(':checked')) { 
        window.location.href="domain_name/your_controller_name/your_function_name"; 
    } else { 
        alert("isnt active"); 
    } 
});
于 2013-06-25T06:23:11.870 回答