![]() |
jQuery Kills PHP Variables - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: jQuery Kills PHP Variables (/showthread.php?tid=12632) |
jQuery Kills PHP Variables - El Forum - 10-25-2008 [eluser]spamguy[/eluser] This is an odd one. Let's say I have a page consisting of jQuery UI tabs. One of the tabs fetches a PHP doc that looks like this: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> $myvar is set in the appropriate controller: Code: function view() When view.php is viewed by itself (that is, not through jQuery tabs), $myvar prints properly. When it's viewed as an AJAX tab, though, I get a PHP error: Quote:A PHP Error was encountered What can I do to fix or circumvent this? Thanks! jQuery Kills PHP Variables - El Forum - 10-25-2008 [eluser]Randy Casburn[/eluser] Hey, If this is a view partial, have you tried removing the <!DOCTYPE>? Randy jQuery Kills PHP Variables - El Forum - 10-25-2008 [eluser]spamguy[/eluser] Gave that a try. No go. jQuery Kills PHP Variables - El Forum - 10-25-2008 [eluser]Randy Casburn[/eluser] Yea - that was stupid anyway. Try: Code: $this->load->vars($data); Let's let CI do the work differently for us. I've had this problem with XMLhttpRequest (AJAX) before. I just can't recall the specifics. (and I'm too tired to look). Randy jQuery Kills PHP Variables - El Forum - 10-25-2008 [eluser]spamguy[/eluser] Nope. Thanks for trying, though. jQuery Kills PHP Variables - El Forum - 10-26-2008 [eluser]Colin Williams[/eluser] Is that really the full controller, or have you simplified it for the sake of making the example more clear? I guess I have a hunch that something else is causing it.. something we cannot see because you omitted it. Also, right after the line that sets $data['myvar'], do [color="green"]print $data['myvar'][/color]. Repeat this until you can potentially spot an area of logic where $data['myvar'] is not set properly. jQuery Kills PHP Variables - El Forum - 10-26-2008 [eluser]Randy Casburn[/eluser] That was my thought initially too Colin. When I had this problem with AJAX I thought I recalled it was because I was setting the $data variable in the __contstruct() method and calling the setter() method directly that used $this->data. As spamguy described, when called with an HTTP request it would work fine, but with an XMLHttpRequest it wouldn't. I ran up against a deadline, moved the variable to the setter() method for $data and it worked. That supports your hypothesis. I'd be curious to know "the rest of the story" as Paul Harvey says. Randy jQuery Kills PHP Variables - El Forum - 10-28-2008 [eluser]spamguy[/eluser] [quote author="Randy Casburn" date="1225051506"]That was my thought initially too Colin. When I had this problem with AJAX I thought I recalled it was because I was setting the $data variable in the __contstruct() method and calling the setter() method directly that used $this->data. As spamguy described, when called with an HTTP request it would work fine, but with an XMLHttpRequest it wouldn't. I ran up against a deadline, moved the variable to the setter() method for $data and it worked. That supports your hypothesis. I'd be curious to know "the rest of the story" as Paul Harvey says. Randy[/quote] Sorry for the delay in getting back to this question. You both are technically right: there is more code than I previously showed. However, I commented it all out and tested before posting it here. As I double-checked my work just now, the solution to this mess hit me. And it's shamefully simple. I have two controllers that use the same private function: 'view' calls it once, 'random' calls it 10 times. 'random' has its own jQuery tab; 'view' does not. Trouble is, $data['myval'] was defined in 'view' but not in 'random'. So for months -- literally months! -- I had myself believing that jQuery was causing PHP variables to die, since undefined variables only happened when jQuery was around. D'oh. ![]() jQuery Kills PHP Variables - El Forum - 10-28-2008 [eluser]Colin Williams[/eluser] Good to hear! It's always something shamefully simple jQuery Kills PHP Variables - El Forum - 10-29-2008 [eluser]Randy Casburn[/eluser] Cool. That's probably what I did too <<sheepish grin>> but never really found out. Glad you got it figured out. Randy |