Welcome Guest, Not a member yet? Register   Sign In
how to get current year
#9

[eluser]John Murowaniecki[/eluser]
You can use jQuery to make a JSON request to a controller such as CodeIgniter below:
Code:
<?php
class Ajax extends CI_Controller
{
    function year()
    {
        print(json_encode(array(
            'long' => date('Y'),
            'short' => date('y')
        )));
    }
    #

}
#
/* eof: controller/ajax.php */
So if you request the url http://yourdomain/yourapplicationfolder/ajax/year you will receive a JSON formated string: {"long":"2011","short":"11"}. So if you need an how-to get data using jQuery.Ajax here“s a tip:
Code:
// <![CDATA[
    $.ajax({
        url: 'http://yourdomain/yourapplicationfolder/ajax/year',
        type: 'GET',
        dataType: 'json',
        success: function(data) {
            alert('long '+data.long+'\nshort '+data.short);
        }
    });
// ]]>

More information about jQuery and Ajax you'll find here http://api.jquery.com/jQuery.ajax/ , if you need to know how json works I recomend you to read http://www.json.org/ .


Messages In This Thread
how to get current year - by El Forum - 07-15-2011, 08:39 AM
how to get current year - by El Forum - 07-15-2011, 08:53 AM
how to get current year - by El Forum - 07-15-2011, 09:38 AM
how to get current year - by El Forum - 07-15-2011, 09:41 AM
how to get current year - by El Forum - 07-15-2011, 09:50 AM
how to get current year - by El Forum - 07-15-2011, 09:51 AM
how to get current year - by El Forum - 07-15-2011, 11:11 AM
how to get current year - by El Forum - 07-15-2011, 11:13 AM
how to get current year - by El Forum - 08-04-2011, 09:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB