Welcome Guest, Not a member yet? Register   Sign In
Accesing jQuery from Controller
#1

[eluser]riko0na[/eluser]
I am using ajax to view the display made from the controller by getting data from the database like this also I use jQuery for the Date(I've showed only this part)

VIEW:
Code:
<head>

<link type="text/css" href="uicore/development-bundle/themes/base/ui.datepicker.css" rel="stylesheet" />

<scr1pt type="text/javascr1pt" src="css/jquery-1.3.2.js"></scr1pt>
<scr1pt type="text/javascr1pt" src="js/ui.core.js"></scr1pt>
<scr1pt type="text/javascr1pt" src="js/ui.datepicker.js"></scr1pt>

$(function() {
    $('#catdatev').datepicker({
        changeMonth: true,
        changeYear: true
       });
    });

<scr1pt type="text/javascr1pt">
    function edCat( strURL )
    {
       var xmlHttpReq = false;
       var self = this;
       var cname = document.edc.catnameed.value;
        if(cname == "")
        {
         cname = "noblanks";
        }
self.xmlHttpReq.open( 'GET', strURL + cname, true );
self.xmlHttpReq.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
self.xmlHttpReq.onreadystatechange = function()
{
if (self.xmlHttpReq.readyState == 4)
{    
   document.getElementById( "showeditdel" ).iinnerHTML = self.xmlHttpReq.responseText;
}
else
{
   document.getElementById( "showeditdel" ).iinnerHTML = '<center><img src="images\/ajax-loader.gif"/><\/center>';
}
}
self.xmlHttpReq.send( null );
}
</scr1pt>
&lt;/head&gt;

&lt;body&gt;

<A oonclick="edCat('admincms/edcategory/');" class="ui-state-default ui-corner-all" style="text-decoration: none; cursor: pointer;">View</A>

&lt;/body&gt;

CONTROLLER:
Code:
function edcategory($cname)
{
  echo 'End Date: &lt;input type=text name=enddate id=catdatev value='.$date.'&gt;'
}

my question is, can I call the jQuery function from the controller with this code? newbie here. . cause it works fine when i call the jQuery function from the view page..also the call from the ajax to controller works fine also,, confuse here :-S
#2

[eluser]Phil Sturgeon[/eluser]
You cannot call jQuery functions (or any JavaScript) from a server-side language like PHP. PHP (and therefore CodeIgniter) does all its work on the server, JavaScript does all its work on the client-side (the users browser) so the interaction between the two goes like this:

1.) CodeIgniter (PHP) works out which controller and which method to use, which then picks a view file.
2.) A view file includes all sorts of HTML, images, CSS, JavaScript, Flash, etc.
3.) jQuery (JavaScript) can then call another CodeIgniter page via AJAX to get a response in a similar way.

And repeat.
#3

[eluser]riko0na[/eluser]
3.) jQuery (JavaScript) can then call another CodeIgniter page via AJAX to get a response in a similar way.

but what if the codeigniter page response via AJAX contains a jQuery function.. would that be possible.. what will i do?.
#4

[eluser]jcavard[/eluser]
[quote author="riko0na" date="1249974486"]but what if the codeigniter page response via AJAX contains a jQuery function.. would that be possible.. what will i do?.[/quote]
Evaluate the response accordingly and it will work.

Have a look here, MALSUP has a neat library which allow you to handle any response. You can have javascript no problem! Good luck
#5

[eluser]riko0na[/eluser]
Phil Sturgeon and jcavard, thank you for your replies.. I've finally got my problem answered just call the jquery again if the codeigniter page response via AJAX contains a jQuery call function..
#6

[eluser]Johan André[/eluser]
[quote author="jcavard" date="1249976355"]
Have a look here, MALSUP has a neat library which allow you to handle any response. You can have javascript no problem! Good luck[/quote]

The taconite stuff looks awesome! I've missed that one... Bookmarked!
#7

[eluser]Phil Sturgeon[/eluser]
Yeah that really is awesome. Good spot!




Theme © iAndrew 2016 - Forum software by © MyBB