AJAX code没有在本地运行 [英] AJAX code do not run locally

查看:106
本文介绍了AJAX code没有在本地运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

code读取子文件夹下面给出

Code to read subfolders is given below

function countFolder(){
    var dir='albums';
    var count=0;
    alert(dir);
    $.ajax({
        url: dir,
        async:false,
        success: function (data) {
            $(data).find("a:contains(" + 'album' + ")").each(function () {// function to read foldera name contains 'album'
                count++;
                //alert(url);
            });
        }
    });
    return count;
}

这code运行完美,当我用它在本地主机。但是它在本地运行(从文件位置IE)时不运行。我有12个子文件夹。所以,当我使用localhost我得到12的输出,但是当在本地运行我只得到了0输出。

This code runs perfectly when I use it on localhost. But it does not run when run locally(i.e. from file location) . I have 12 sub-folders. So when I use localhost I get the output of 12, however when run locally I only get the output of 0.

会是什么问题?请帮我.. 我是新的使用jQuery。所以,如果这是我的错,请通知吧。 在code我只使用HTML,jQuery的,JS,但不是PHP的。

What would be the problem? Please help me.. I am new with jQuery. So if it is my mistake please notify it. In code I only use html, jQuery, js, but not php.

推荐答案

这是因为浏览器跨域策略。您不能发送发出请求已发送外域AJAX请求。所以基本上,你不能用ajax在本地都没有。

This is because of Browsers cross-domain policy. You can't send ajax request outside the domain from which the request have been send. So basically, you can't use ajax locally at all.

这篇关于AJAX code没有在本地运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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