locked
Xml file access from Jquery/Javascript RRS feed

  • Question

  • User527076549 posted

    Is it possible read /check if file exists using jquery ?

    and how to do it ?

    Monday, May 13, 2019 7:45 AM

Answers

  • User753101303 posted

    Hi,

    I assume you mean a client side file ? No, a browser runs as a " sandbox" for safety reasons. You have access to a file only if it this file is explictely selected by a user.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 13, 2019 8:38 AM

All replies

  • User753101303 posted

    Hi,

    I assume you mean a client side file ? No, a browser runs as a " sandbox" for safety reasons. You have access to a file only if it this file is explictely selected by a user.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 13, 2019 8:38 AM
  • User-2054057000 posted

    If the file exists on the same virtual directory of the website then you can simply make an ajax call to read it. 

    This is how to do it:

    Read XML file with jQuery

    Monday, May 13, 2019 3:33 PM
  • User61956409 posted

    Hi Amitha,

    Is it possible read /check if file exists using jquery ?

    and how to do it ?

    Please clarify more about your scenario and question, so that we can better understand and help achieve it.

    Besides, I assume that the XML file is accessible, you can refer to the following code snippet to process the XML file using Jquery.

    $.get("https://xxxxx/xxxfolder/test.xml", function (data) {
        $(data).find('Student').each(function () {
            var sname = $(this).find('Name').text();
            var sgender = $(this).find('Gender').text();
    
            console.log("Name: " + sname + ", Gender: " + sgender);
        })
    });

    Test XML:

    <?xml version="1.0" encoding="utf-8" ?>
    <StudentList>
      <Student>
        <Name>fei han</Name>
        <Gender>male</Gender>
      </Student>
      <Student>
        <Name>fei han1</Name>
        <Gender>male</Gender>
      </Student>
    </StudentList>
    

    Test Result:

    With Regards,

    Fei Han

    Friday, May 17, 2019 3:26 AM