Reputation: 937
Alright, I have no idea how to put this question but I'm trying to keep it short and understandable.
So I've been following this tutorial. (for the full code)
I've modified the code a bit to my liking but I get this error
GET http://sample.com/refresh.php/?lastTimeID=0 404 (Not Found)
(This is from browser developer console)
This is the code where it goes wrong, I think..
var lastTimeID = 0;
$(document).ready(function() {
$('#btnSend').click( function() {
sendChatText();
$('#chatInput').val("");
});
startChat();
});
function startChat(){
setInterval( function() { getChatText(); }, 2000);
}
function getChatText() {
$.ajax({
type: "GET",
url: "/refresh.php?lastTimeID=" + lastTimeID
}).done( function( data )
{
var jsonData = JSON.parse(data);
var jsonLength = jsonData.results.length;
var html = "";
for (var i = 0; i < jsonLength; i++) {
var result = jsonData.results[i];
html += '<div>(' + result.chattime + ') <b>' + result.usrname +'</b>: ' + result.chattext + '</div>';
lastTimeID = result.id;
}
$('#view_ajax').append(html);
});
}
function sendChatText(){
var chatInput = $('#chatInput').val();
if(chatInput != ""){
$.ajax({
type: "GET",
url: "/submit.php?chattext=" + encodeURIComponent( chatInput )
});
}
}
This is what I'm confused about; it shows http://sample.com/refresh.php/?lastTimeID=0
But where does it get the "/" after refresh.php? Is this supposed to happen? Something to do with .htaccess
?
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ /admin/$1/ [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /admin/index.php/$1 [L]
How do I fix this error?
Just like I said, I have no clue on how to ask this correctly.
And another little question; is it appropriate to look at the browser developer console?
If you need more information, feel free to ask!
Thanks in advance.
Upvotes: 3
Views: 118
Reputation: 2517
Add data in you ajax request, like so:
type: "GET",
url: "/refresh.php",
data: {
lastTimeID:lastTimeID
},
... this will leave your function looking like this:
Replace full function.
function getChatText() {
$.ajax({
type: "GET",
url: "http://sample.com/refresh.php",
data: {
lastTimeID:lastTimeID
},
}).done( function( data )
{
var jsonData = JSON.parse(data);
var jsonLength = jsonData.results.length;
var html = "";
for (var i = 0; i < jsonLength; i++) {
var result = jsonData.results[i];
html += '<div>(' + result.chattime + ') <b>' + result.usrname +'</b>: ' + result.chattext + '</div>';
lastTimeID = result.id;
}
$('#view_ajax').append(html);
});
}
Upvotes: 0
Reputation: 937
So after the help of EricG, I disabled the whole .htaccess which caused the problem, which means that there is a line in there you should try to comment one by one. I didn't need to use the .htaccess. But you should consider checking your .htaccess (or disabling it if not used)
Credits to EricG and all others who tried to help me out!
Upvotes: 1