Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

404 error because of AJAX?

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.

like image 460
Sj03rs Avatar asked Dec 05 '25 03:12

Sj03rs


1 Answers

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!

like image 195
Sj03rs Avatar answered Dec 07 '25 21:12

Sj03rs



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!