Jquery: Running AJAX locally without a webserver

前端 未结 7 858
孤独总比滥情好
孤独总比滥情好 2020-11-30 13:36

I have the following function in a .js file in index.html

function getValues(){

 $.ajax({
   type: \'POST\',
   url: \"http://localhost/getData/getdata.php\         


        
7条回答
  •  感情败类
    2020-11-30 14:26

    When you run your index.html from a file the AJAX works. But the problem occurs because you are viewing the file at address "file://....../index.html" and you are making a AJAX request to "http://localhost/..../something.php" which IS NOT ALLOWED because of cross site scripting. All AJAX requests must go to the same domain/server.

    This is a assuming that you are viewing the file by double clicking it and still making the AJAX request to the web server.

提交回复
热议问题