質問

I want to fetch a table from a .html file and show it in a div in my .html.erb file... I tried with loading a simple .txt file as below but its now working.. Please let me know what changes are to be done. Am I going wrong in giving the path??

app/view/account/show_result.html.erb:

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script type="text/javascript">

    function showy(count){
         alert(count);
        $("#quickview").load("D:\sample.txt");
        return true;
     }

</script>
</head>
<body>
<h3>Recent Test Results</h3><br>
<div id ="quickview">
    HELLO
</div>
// for loop with index i
<a id="repo" href="" onclick="showy(<%= i %>)" >Quick view!</a>
//some other code
</body>
</html>

Update1: I actually want to access a HTML file in the public folder of my app. The path goes like this.. RORapp/public/reports///.html file

      $("#quickview").load("http://localhost:3000/reports/"+userid+"/"+fold+"/overview.html #overviewTable");

Update2:

When I just the copy the url(http://localhost:3000/reports/"+userid+"/"+fold+"/overview.html) and open in browser, i can see the html page.. But when i try to load a part of it, I'm not able to do it..In cmd , I get an error saying

AbstractController::ActionNotFound (The action 'reportng' could not be found for AccountController):

account is my main controller, and reportng is the css file used for styling of that html page

On checking the console for errors, I got the following error ( on pressing F12 in browser)

TypeError: element.dispatchEvent is not a function
fire()protot...?body=1 (line 4072)
element = Object[Document show_test_results]
eventName = "dom:loaded"
memo = undefined
_methodized()protot...?body=1 (line 257)
fireContentLoadedEvent()protot...?body=1 (line 4106)
[Break On This Error]   

element.dispatchEvent(event);

Solution: Now apart from loading the reqd html file , I'm able to change the attributes too :)

    function showy(count){
        var linkDiv = $('#repo_'+count);
        var fold = linkDiv.data('folder');
        var userid = '<%= self.current_user.id %>';
        var server = '<%= request.host_with_port %>';

        $( "#success_"+count ).load( "http://"+server+"/reports/"+userid+"/"+fold+"/overview.html #overviewTable" , function(){
            $("#success_"+count).find("a").attr("href","http://"+server+"/reports/"+userid+"/"+fold+"/suite1_test1_results.html");
        });

         **SOME CODE**

}
役に立ちましたか?

解決

AJAX calls to locations local to the client machine are blocked by the browser for security reasons.

For this to work you need to put it online, or use a local server, eg: http://localhost/mysite

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top