user8317585
user8317585

Reputation:

How to call controller from javascript CodeIgniter

I need to call a controller from javascript. I've already success to call the controller, but if the controller has no paramater. In my cases, the controller has a parameter. How can i can call the controller from javascript

Javascript code:

<script language="javascript" type="text/javascript">  
var thisTable = setFilterGrid("myTable");

document.getElementById("oneday").onclick = function() {
    var date = new Date();

    var day = date.getDate().toString();
    var month = date.getMonth().toString();
    var year = date.getFullYear().toString();

    var oneday = day.concat('/', month, '/', year);

    window.location.href = "<?php echo site_url('sellbyitem/retrieveInfo('/*howcanipassonedayhere*/');?>";
};

Controller:

public function retrieveInfo($date) {
    echo $date;
}

I've already looking for same cases, but it doesn't work for me

Upvotes: 0

Views: 742

Answers (1)

B. Desai
B. Desai

Reputation: 16436

You can pass javascript parameter at end like following :

window.location.href = "<?php echo site_url('sellbyitem/retrieveInfo/');?>" + oneday ;

Upvotes: 3

Related Questions