开发者

Issue passing variable from javascript to controller Codeigniter

开发者 https://www.devze.com 2023-01-06 15:44 出处:网络
I\'m struggling with this and just can\'t seem to make it work. Need to pass the current users date (cdate) variable to my controller and in spite my alert windows shows the correct value, that value

I'm struggling with this and just can't seem to make it work.

Need to pass the current users date (cdate) variable to my controller and in spite my alert windows shows the correct value, that value never reaches the controller.

Here's the javascript code:

$(document).ready(function() {  
    $('#submit').click(function() {  
        var mydate=new Date()  
        var year=mydate.getYear()  
        if (year < 1000)  
            year+=1900  
        var day=mydate.getDay()  
        var month=mydate.getMonth()+1  
        var daym=mydate.getDate()  
        if (daym<10)  
            daym="0"+daym  
        if (month<10)  
            month="0"+month  
        var hours=mydate.getHours()  
        var minutes=mydate.getMinutes()  
        var seconds=mydate.getSeconds()  
   开发者_运维知识库     var cdate=+month+"/"+daym+"/"+year  
        $.post('user/available', {curdate: cdate});  
        alert(cdate);         
    });  
});    

Controller:

$curdate=$this->input->post('curdate');  

View:

echo form_open('user/available');  
echo form_input('dateav','',$dateav);  
input type="image" src="echo base_url();images/send.png" id="submit" alt="Submit button"   
echo form_close();  

Can anyone tell me what i'm doing wrong?


I suggest to dump the whole request to stdout or something so you can see what URL is used and all the other parameters. Maybe there is a typo in the config.

[EDIT] The function should return false, otherwise Bad Things(TM) will happen (like the form will be posted twice and such).

If nothing happens but the alert showing up, then the post() call fails. Read the documentation and especially the part about error handling with .ajaxError()

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号