Ajax post to a php file in a directory not working

坚强是说给别人听的谎言 提交于 2021-02-11 08:06:14

问题


I'm using Ajax request for a project and i has lot of problem to make it working I sommetime receive some error 500 (Internal Server Error), but finally everything works until I wanted to move my scripts into a directory.

Here is my Ajax works :

    var xhr = getXMLHttpRequest();
    xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
        callback_like(xhr.responseText, receive);
         location.reload();
      }
    };
    xhr.open("POST", "like.php", true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    var data = "like=" + receive;
    xhr.send(data);

And this one doesn't work :

    var xhr = getXMLHttpRequest();
    xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
        callback_like(xhr.responseText, receive);
         location.reload();
      }
    };
    xhr.open("POST", "script/like.php", true);
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    var data = "like=" + receive;
    xhr.send(data);

Error message in the console : POST: 'url' 500 (Internal Server Error)

I already tried to set all the right to the directory but nothing change..

Thanks


回答1:


An internal server error means that there is probably an error in your code. Any references or includes of other files that need to be adjusted? If the file wouldn´t be found you´d get a 404 Not Found in your response.

Enable error output in php to get a more detailed error message from php.



来源:https://stackoverflow.com/questions/39692014/ajax-post-to-a-php-file-in-a-directory-not-working

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!