0

i have this Fiddle Here http://jsfiddle.net/kd6Y4/1/

which is getting div from a different page on same site and display it the problem is its working perfectly online like this direct link http://fiddle.jshell.net/kd6Y4/1/show/ search for hand or and in both

but its not working offline due to cross site scripting restriction please help make it work offline as i need to use this offline in a android environment and also in offline browsers

  $("#searchForm").submit(function (e) {
 e.preventDefault();
var results = $("#resultContainer");
var text = $("#search").val();
results.empty();
$.get("url here", function (data) {
var els = $(data).find("div:contains(" + text + ")").appendTo(results);
els.find('a').attr('href', function (_, href) {
    return 'url here/#' + $(this).closest('div').attr('id');
})
});
 });

[this error is coming how to resolve]

XML Http request cannot load file no "access control allow origin" header is present on the requested resource origin stuff is therefore not allowed access

user3048414
  • 23
  • 1
  • 7

1 Answers1

0

Try

jQuery(function(){
    $("#searchForm").submit(function (e) {
        e.preventDefault();
        var results = $("#resultContainer");
        var text = $("#search").val();
        results.empty();
        $.get("test2.html", function (data) {
            var els = $(data).find("div:contains(" + text + ")").appendTo(results);
            els.find('a').contents().unwrap();
            els.wrap(function(){
                return $('<a/>', {
                    href: 'test2.html#' +this.id
                })
            })
        }, 'html').fail(function(){
            console.log('arge', arguments)
        });
    });
})

and to make local files work follow this question

Community
  • 1
  • 1
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531