简体   繁体   中英

Writing to XML file using jQuery

Is there any way to write to a xml file using jQuery?

This is my directory

- root
    - css
        popup.css
    - js
        jquery.js
        ajax.js
    - xml
        data.xml
    popup.html
    popup.js
    manifest.json

my ajax.js reads the xml data and checks if the particular person is registered, if it is, it alerts the user that the username is taken, else i want to register that person on data.xml file.

$(document).ready(function() {
    var account = [];

    $.ajax ({
        url: 'xml/data.xml',
        dataType: 'xml',
        type: 'get',
        cache: 'false',

        success: function ( xml ) {
            // :: Pushing Registered People in Account Array
            $(xml).find('record').each(function(){
            account.push({
                    username: $(this).find('username').text(),
                    master: $(this).find('master').text()
                });
            });

            // :: When Submit Button is Clicked
            $('#submitReg').click(function(){
                var found = false;
                for ( i=0; i<account.length && !found; ++i ) {
                    if ( account[i]['username'] == $('#usr').val() ) found = true;
                }

                // :: If Username Already Exists
                if ( found ) {
                    $('#errorStatus').html('Username Already Exists');
                    $('#usr').val('');
                    $('#pwd').val('');
                }
                else {
                    // :: Write to file
                }
            });
        }
    });
});

Files are local and aren't hosted, so i won't be using PHP or ASP.NET for any manner. (EDIT: ie i want my data.xml to be stored on a computer/laptop/device on who ever is using this extension).

my data.xml is

<?xml version="1.0" ?>

<details>
    <record>
        <username>Danyal Imran</username>
        <master>1982gonzopracontroli</master>
    </record>

    // :: ADD MORE RECORDS HERE 

</details>

I want newly Registered Username and Master(Password) be wrapped in a xml format and written to data.xml

Registration Page:

<div id="registrationPanel"> 
    <input type="text" class="form-control" id="usr" placeholder="Enter Desired Username">
    <input type="password" class="form-control" id="pwd" placeholder="Enter Master Password">
</div>

Your extension's directory is read-only for the extension, and the rest of the filesystem is not even readable.

Note that if you try to change any files there on a non-development install, Chrome will immediately consider that the extension was tampered with and permanently disable it - it saves cryptographically signed hashes of all files. So, it's not possible to install-then-configure the extension via a file.

You should store your data in some other storage: for instance, chrome.storage . If you need to provide a way to export data as a file, you can use chrome.downloads API for it.

Note that Chrome does not provide a safe, encrypted storage accessible from an extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM