如何在没有 Web 服务器的情况下运行 ajax 代码? [英] How can I run ajax code without web server?

查看:56
本文介绍了如何在没有 Web 服务器的情况下运行 ajax 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的系统上没有服务器的情况下运行 ajax,我用这个创建了一个 index.html.

I am running ajax without a server on my system, I have created one index.html with this.

JavaScript 函数:

function do_the_click(url)
{
alert('inside this method do_the_click');
    $.ajax({
                         async: false,
                         url : url, 
                         contentType: "text/html",
                         type : "GET",
                         dataType : "text/html",                
                         success: function(data){
                         alert('data');
           }});
} 

我的 HTML 正文内容是:

My HTML body content is:

<a href="Java Collections.html" class="button" id="javacollections" onclick="do_the_click('this.href');"/>Java Collections</a>

我能够在警报窗口中获取此消息在此方法中do_the_click但无法在警报窗口中获取数据,因此无法获取在 index.html 中获取页面 Java Collections.html,

I'm able to get the this message in alert window inside this method do_the_click but am not able to get the data in alert window, and so not able to get the page Java Collections.html in the index.html,

我在 Google re 上搜索了很多.如何在不使用 jquery.ajax 中的服务器的情况下在本地加载数据,但我没有找到任何好的解决方案,所以我认为如果它驻留在堆栈溢出中对其他人也有好处.

I have searched very much on Google re. how to load the data locally without using server in jquery.ajax but I didn't find any good solution, so I think that its good for others as well if it resides on Stack overflow.

推荐答案

我可以在没有网络服务器的情况下运行 ajax 问题出在我的代码下面,我在我的文件系统上运行的代码你也可以使用它.

I m able to run the ajax without webserver the problem was with my code the code written below that i had run on my filesystem u can use that as well.

      function do_the_click(brl)
      {
          alert('inside this method do_the_click');
          alert(brl);
          var request  =     $.ajax({
                    async: false,
                    url: brl, 
                    contentType: "text/html",
                    type : "GET",
                    dataType : "html",                
                });

                request.done(function( msg ) {
                          alert(msg);
                          $( "#contentarea" ).load( msg, function() {
                                    alert( "Load was performed." );
                          });
                });

                request.fail(function( jqXHR, textStatus ) {
                          alert( "Request failed: " + textStatus );
                });

      }

Java 集合

这篇关于如何在没有 Web 服务器的情况下运行 ajax 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆