Yii Ajax success Javascript won't go away - ajax

I'm running Apache2 on Ubuntu 12.10, and yii 1.1.13
I have an ajax request that looks like this:
echo CHtml::dropDownList(
'id',
$model->value,
$model->values,
Array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('myurl'),
'update'=>'#myId',
'data'=>array(
'first'=>'value',
'second'=>'value',
),
)
);
In the past, I tried adding a line after 'data' that looked like this:
'success'=>"function(html){jQuery("#myId").html(html)}});return false;}"
I've since deleted it. For some reason, this keeps showing up on my page.
I've tried the following:
Restarting entire server
Deleting entire browser cache, and even having a friend who has never seen the site before load it
Grep my entire web directory for that line of code
I have not been able to find any trace of this stupid line, but it won't go away. Please help, I'm starting to question my sanity.

'update'=>'#myId', // this line indicates which selector would be updated after ajax success
Because above line also renders the same what the removed code acts
'success'=>"function(html){jQuery("#myId").html(html)}})

Related

Laravel doesn't authenticate on server but does on local machine

I just uploaded a project from my local machine via FTP and it seems that the live server is working differently after trying to log in.
On the live server it's not authenticating. It gets to the __construct on AuthController.php but goes right back without errors (again, on local it works fine).
I tried adding this in Authcontroller.php:
public function postLogin(Request $request){
die();
}
And it didn't even reach it on server (it did on local).
I tried playing with the routes and instead of this:
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
I did this:
Route::post('auth/login','Auth\AuthController#postLogin');
Route::get('auth/login','Auth\AuthController#getLogin');
Didn't help on the server (local still worked fine).
I tried clearing my browser's cache, artisan cache, artisan config cache and basically anything I could find.
I tried re-uploading files from local to the server and nothing seems to work.
The most important thing here (I think) is that when I created the postLogin function it didn't even go in. That should be a huge tip if I actually knew what that meant.
The log didn't give me any errors.
Thank you #Bagus Tesa for asking to see the login file!!!
In the action of the form I added a parameter I was using for something but for some reason that's what was screwing everything up.
The important thing is that it works now...
Thanks so much!

Cakephp randomly drops session

Recently I moved my cakephp site from a hosting service to an other. The page was working like a charm, but now I'm having the issue, that my sessions randomly drop.
I'm on a shared hosting service, so I changed cake's session defaults from php to cake, now my sessions are saved to my tmp/sessions folder. (but it wasn't working with php either)
Followed my session's way with Firebug:
When i log into the page, i have a Sessionid, and in the tmp/sessions folder i have the corresponding sess_{sessionid} file too.
After a few clicks on some pages (totally random) my sessionid changes and i'm "logged out".
The session file with which i've logged in, remained in the directory.
My session settings in core.php right now:
Configure::write('Session', array(
'defaults' => 'cake'
));
I'm using the 2.3.8 version of Cake.
Update:
Finally i found the problem thanks to Nick. I checked the Cakephp error files, and found out that i only got logged out, when i visited a page containing an element, which was not on the server ( eg a picture was missing). So i went to Firebug, and check what the Net tab says. On the new Host service i got a 404 Not Found response AND a new session id set in the response, whilst on the other servers i tested the page, i simply got a 404 Not Found. If i randomly generate links to not existing files like (domain/test.jpg) i get the same results.
Try these settings, in Firefox you can install the web develop extension, then you can view your cookie to see if it is all set correct.
Configure::write('Session', array(
'defaults' => 'php',
'cookie' => 'yourdomain',
'timeout' => 44640,
));
Check any components that you are using for whitespace (usually at the end of the file).
I came across this recently whilst helping a client with their existing CakePHP site, when logged in one particular page that called a component was killing $this->Session->read(‘Auth’).
There is a CakePHP shell that you can use to find whitespace.

WordPress Ajax Get Request?

I have a page that includes a php file I have written like so
HTML
<div id="playlists_div_holder">
<?php include(dirname(__FILE__) . '/includes/get_playlists.php'); ?>
</div>
I have created a button that will refresh the playlists , incase the user has uploaded (added/removed) anything, and I am trying to do so with an ajax request to get the file and include it back into that div, but I am receiving a 500 error.
I am doing this in WordPress so that may be an issue.
The Button
<span class="button-primary refresh-playlists" onclick="ReloadPlaylists()">Refresh Playlists</span>
Ajax Request
function ReloadPlaylists() {
jQuery.get('<?php echo plugins_url();?>/Player/includes/get_playlists.php', function(data) {
jQuery('#playlists_div_holder').html(data);
alert('Load was performed.');
});
}
Including it works but an ajax get throws a 500 error
It's pretty hard to guess the problem but some simple workarounds that you can use all the time:-
CAUTION! Please take backup of your WordPress before doing anything.
1st workaround:-
Download fresh WordPress copy
Delete every folder, except the wp-content folder.
Upload all the files and folders again, except the wp-content folder.
2nd workaround:-
Rename
wp-content/themes
to
wp-content/themes-backup
Create a new folder:-
wp-content/themes
start copying each theme from themes-backup to themes one by one and see if the error is gone.
Now what you have done with the themes folder, do exactly with the plugins folder.
Based on your comment,
i'm getting call to undefined function get_option on line 8 , which is odd because it works when i include it the first time. Could it be because its calling the same file on the other and it has some sort of variable conflict?
This is because when the plugin in running as an include, all the wp-includes are laoded before your plugin code is execute. However when you make an AJAX call directly to that file, the wp-includes are no loaded hence your get_option() isn't working.
You can fix that by adding include_once("../../../wp-blog-header.php"); on top of your get_playlists.php file. That might break your plugin (not sure) so in that case its safe to use it inside a condition like this
if(stristr($_SERVER["REQUEST_URI"], get_playlists.php))
include_once("../../../wp-blog-header.php");
However once you do that you will get an Error 404 when you make an AJAX request because that URL is not registered in Wordpress URL Rewrite. You can override that by using header() function.
if(stristr($_SERVER["REQUEST_URI"], get_playlists.php)) {
include_once("../../../wp-blog-header.php");
header("HTTP/1.1 200 OK");
}

Facebook SDK breaking Codeigniter? Blank page

I have tested my login script on my localhost with no problems.
I have now uploaded it online as can be seen at this link
Obviously if you click, you can see that a blank page is displayed and I have no idea why.
I did a test of a little bit of content, and removed the Facebook SDK code.
//Facebook config (required for library)
$fb_config = array(
'appId' => 'REMOVED',
'secret' => 'REMOVED'
);
//Load Facebook library
$this->load->library('facebook', $fb_config);
//SET FACEBOOK USER
$fbuser = array();
$fbuser = $this->facebook->getUser();
When the above code is not present, the page loads.
I have updated my app setting correctly, namely changing the site URL fro http://localhost to http://gua.com so i dont believe it is that.
I have even changed my CI settings to show all errors - nothing is shown.
Does anyone have any suggestions as to why the above code might be making a blank page load ONLY when it is hosted online?
Many Thanks
THomas
Open up the base_facebook.php and try removing either of these two lines from the top.
if (!function_exists('curl_init')) {
throw new Exception('Facebook needs the CURL PHP extension.');
}
if (!function_exists('json_decode')) {
throw new Exception('Facebook needs the JSON PHP extension.');
}
If you stop getting the white screen, it should indicate that your sever needs either curl or json_decode enabled.
Alternatively you could just do a echo phpinfo() and check if they are enabled. Note that json_decode/encode is only available in php >=5.2
If your localhost was a Windows box and your remote host is a *NIX system, there is a chance that some extra white space was introduced into your SDK files outside of the <?php ?> tags. This can sometimes cause the "white screen of death" when this whitespace is output and sets the headers.
Try downloading a fresh copy of the SDK from Github and don't unzip it until it is on your remote server. Better yet, if you ssh access wget it or git clone it directly there. See if that helps.
If it doesn't, add error_reporting(E_ALL) as the first line of your script and see if that tells you anything.
You will need to run chmod eg: "sudo chmod -R 777 facebook/". I think the files were written in or for windows so on a *Nix system it does not run till that is checked.
In my case after doing this, I started to have errors I could work with.

cakephp 2.0 upgrade shell redirect() faulty?

I am upgrading an application from cakephp 1.3 to 2.0 and running into some problems. I can't quite figure out what is going on behind the scenes with my redirect statements. This has been happening since I ran the upgrade shell.
If I put this in my controller the redirect works perfectly:
function redirect() {
$this->redirect(array('controller' => 'user', 'action' => 'partners'));
}
This, however, does not work for me:
function redirect2() {
echo 'made it';
$this->redirect(array('controller' => 'user', 'action' => 'partners'));
}
This isn't a function I am using, it is just the simplest form of the problem I have isolated.
I know I shouldn't be displaying things from the controller, but my question is what is going on behind the scenes that is causing the redirect to not function? The result for the redirect2() is it prints "made it" on the screen and then stops. No errors, no redirects, no showing the view for redirect2. I have checked the error logs and there are no errors.
The confusing thing is that when I was using 1.3 all my redirects worked fine, and now something isn't working with some of them.
Thanks for any help,
you are not allowed to echo anything except for http headers prior to a php redirect.

Resources