Jquery: Running AJAX locally without a webserver

前端 未结 7 855
孤独总比滥情好
孤独总比滥情好 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:22

    I'm tickled pink with myself because reading the answers people posted about how you can't do AJAX "locally" without a Web server led me to the solution as to how you can do it. With JavaScript, the XMLHttpRequest() object's methods are mostly produced by the browser and you need to leave out the one produced by the Web server (xmlhttp.status == 200). The following works:

    
    
    
    
    

    AJAX Request/Response

提交回复
热议问题