How can I load a local file using jQuery? (with file://)

前端 未结 2 495
时光说笑
时光说笑 2021-01-18 03:10

Is there any way to load data from a data file (eg a JSON .js file) using jQuery?

eg:

$.get(\"file:///C:/objectData.js\", function() { alert(\'Load         


        
2条回答
  •  青春惊慌失措
    2021-01-18 03:37

    I hope it is possible. I'd tried it. the Html code and text files resides in the same folder.

    Here is jQuery part.

    $(document).ready(function()
    {
        $("select").change(function()
        {
    
    
            file_name = $("select").val();
            $('#span_result').load(file_name);
        });
    });
    

    The Html code is


    Contents of the file will be displayed below

    Itworked for me in firefox. Sorry if it failed with you.

提交回复
热议问题