Ajax call failed only on localhost - php

I have an ajax call for login:
$.ajax({
url: url_to_ajax,
success: function ( data ) {
switch (data) {
case "-2": input1.addClass("has-error");
break;
case "-1": input1.addClass("has-error");
break;
case "0": input2.addClass("has-error");
break;
case "1": //everythings ok
window.location.replace(base_url);
break;
default: //this should not happens
window.location.replace(base_url);
break;
}
}
});
And chrome console gives me this:
GET http://testserv.local/profil/login_call/admin#gmail.com/ross 404 (Not Found)
When I copy this URL in browser, everythings is ok and it shows me result code. On live server is everything ok. But on localhost this.. And for me, the biggest mistery is, that the url is called with that ajax, because after refresh page I'm logged in..
Can someone help me?
I am using wamp, Apache 2.4.9, PHP 5.5.12 on windows 8.1
EDIT: I was writing this code a month before, everythings were ok on live and on localhost.. After I formated disc and install new W8.1 this code doesn't work.

After 6 hours i resolved it.. Just put
header("HTTP/1.1 200 OK");
In your code if you have the same "magic" problem as me..

It's not a problem with AJAX, but with the server.
The error that you're getting is 404 Not Found. That means that the web server at "testserv.local" exists and is responding, but couldn't find the resource you're looking for. Have you made any change to the local server, recently? What happens if you open http://testserv.local/profil/login_call/admin#gmail.com/ross on your browser? And what about each of:
http://testserv.local/profil/login_call/admin#gmail.com
http://testserv.local/profil/login_call/
http://testserv.local/profil/
http://testserv.local/
(I am asking this because if you're using those urls, maybe the mod_rewrite in Apache stopped working because you changed some configuration)

Related

URLs not found after configuring virtual host on XAMPP

I have a $.get() AJAX call to response.php but after configuring a virtual host on XAMPP I get this error :
jquery.js:9631 GET http://mipl.local/response.php?operation=delete_node&code=Power_source&text=fsfsfsssddfsfs 404 (Not Found)
'mipl.local' is the server name after configuration. Here is my code where I make the AJAX call:
$.get('response.php?operation=delete_node', {
'code': data.node.parent,
'text': data.node.text
});
Any suggestions please?
I fixed the problem with adding the global url not the short one

codeigniter sends blank page

I faced today a strange problem wich I cannot explain.
The Environment:
Ubuntu 16.04
Nginx 1.10 with php-fpm
php 7.0.8
So I migrated from a hosted server with apache and php5 to this new Server.
The first tests were successful. The page was running and seemed to be fine.
Then I encountered the Problem, that some pages couldn't be called. The HTTP response was 200 but the page was blank.
Chrome told me net::ERR_CONTENT_DECODING_FAILED
I found out, that the difference between working pages and the blank pages were, that the non-controller echoed json_encode() at the end;
This is my controller:
public function some_controller()
{
$result = ["test" => "abcde"];
echo json_encode($result);
}
This will end with net::ERR_CONTENT_DECODING_FAILED
This is my workarround:
public function some_controller()
{
$result = ["test" => "abcde"];
echo json_encode($result);
exit();
}
So following is unclear:
Why I have to exit() my controller now?
What is CI doing after a Controller function is passed?
Why was that working with Apache and PHP5? What could be the difference now?
Thank you all
I found the problem by myself.
After installing php7.0-xml the issue went away.
But can anyone tell me why the xml module is required for JSON responses?
Maybe its not the JSON, it is codeigniter wich needs the XML Module (After the controller is passed)?

CakePHP : REST API 404 Error

I have build a REST server and trying to make my java application communicate to it.
But I keep getting a 404 error.
When I type in the url in my browser along with the function name like:
[url]/controller/functionname/1.json
it works fine, returning me the right data.
Without the function name:
[url]/controller/1.json
I get this error:
"action 1.json not defined in controller".
I've checked my .htaccess file and routes against a previous version I had build which was working just fine. I can't figure out what the problem might be. Any suggestions?
And oh, I should mention, the earlier version that I talked about was build on windows and this one on ubuntu.

jQuery AJAX simple PHP Post not working

I've got a very basic one today! I'm trying to post from jQuery to a PHP file hosted on localhost.
My JS:
$("#searchNameButton").click(function() {
var name = $("#searchNameText").val();
$.ajax({
type: 'POST',
url: 'localhost:8080/getNameInfo.php', // -> this works fine from the browser
// data: { name: name }, -> commented out
success: function(){
alert('request successful');
},
error: function(xhr, textStatus, errorThrown){
alert('request failed');
}
})
});
My PHP file (getNameInfo.php), a very basic one for testing:
<?php
echo 'TEST';
?>
In jQuery, it will always bring me to error, saying 'Internal Server Error'.
I am using Ripple Emulator and this is what appears in the console:
POST https://rippleapi.herokuapp.com/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=localhost%3A8080/getNameInfo.php
500 (Internal Server Error)
I assume it has to do more with this than with what's written in the files. Any advice? Thanks!
EDIT: Found this: LINK but it won't fix my issue. If I do what it says here, I won't get any error thrown ("" instead) but will still fail.
EDIT 2: If I set Cross-Domain Proxy to Local in Ripple (that's suggested in the link above) I get
OPTIONS http://localhost:4400/ripple/xhr_proxy?tinyhippos_apikey=ABC&tinyhippos_rurl=http%3A//localhost%3A8080/getNameInfo.php net::ERR_CONNECTION_REFUSED
EDIT 3: Changed my URL to local
C://Mobile//Cross-Platform//TestApp//www//php//getNameInfo.php
and it's working now. Have no idea how to make it work on localhost. BUt will go with this now, as it's only a learning app.
Add a header access control at top of getNameInfo.php file :
header('Access-Control-Allow-Origin: *');
So, finally I found a solution.
Even though it's not a recommended one, running Chrome with
--disable-web-security
will allow me to call a PHP script hosted on localhost:8080 from localhost:3000 where PhoneGap / Ripple Emulator stays.

500 internal server error after updating Apache httpd to 2.2.24

We are working on a project which is build upon Codeigniter 2.
All was working great untill we updated the Apache httpd from 2.2.21 to 2.2.24. The PHP version is still the same (5.3.25).
For building views we use the Template library from Phil Sturgeon.
A controller function could look something like this:
public function index(){
if($this->_is_logged && $this->_is_super){
redirect('/start', 'refresh');
}else{
$this->template
->set_partial('page_header', 'web/template/page_header',$this->data)
->set_partial('page_footer', 'web/template/page_footer')
->set_partial('page_notifications', 'web/template/notification_view',$this->data)
->set_layout('minimum')
->build('start/authenticate_view');
}
}
After the update this causes a 500 Internal server error ...
However, when adding an echo before the ifstatement like this:
public function index(){
echo $this->_is_logged.' '.$this->_is_super.' -- test --'.$this->data;
if($this->_is_logged && $this->_is_super){
redirect('/start', 'refresh');
}else{
$this->template
->set_partial('page_header', 'web/template/page_header',$this->data)
->set_partial('page_footer', 'web/template/page_footer')
->set_partial('page_notifications', 'web/template/notification_view',$this->data)
->set_layout('minimum')
->build('start/authenticate_view');
}
}
The page gets build as it should with the values from the echo at the top of the page.
We allready downgraded the Apache httpd to 2.2.21 and everything worked again without changing any code. So we are sure it has something to do with the Apache version. Maybe it has to do with code used in the Template library, or some strange other thing... ?
We are running up against the walls on this one.
Is there anyone who had the same issue, knows what the problem might be, ... You would be our hero forever :)
Additional info:
We use DataMapper ORM for CI models
cPanel-version: 11.36.1 (build 6)
OS Linux
A 500 error should record an error in your error logs unless you have set it not to. try putting a htacess file in the root with something like:
php_value log_errors 1
php_value error_log /var/www/.....php-error.log
then replicating the error and seeing what is output to the log. As you say it will be to do with some conflict with apache but a 500 error is just too generic to solve.
We found the problem.
There was a forgotten Library we had used in an early state of the project to log messages and data in FirePhp.
Removing this file and a call to one of his functions in our base controller solved the internal server error.

Categories