简体   繁体   English

使用jQuery写入XML文件

[英]Writing to XML file using jQuery

Is there any way to write to a xml file using jQuery? 有什么方法可以使用jQuery写入xml文件吗?

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. 我的ajax.js读取xml数据并检查是否已注册该特定人员,如果已注册,它会提醒用户该用户名已被使用,否则我想在data.xml文件中注册该人员。

$(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. 文件是本地文件,没有托管,因此我不会以任何方式使用PHP或ASP.NET。 (EDIT: ie i want my data.xml to be stored on a computer/laptop/device on who ever is using this extension). (编辑:即,我希望将data.xml存储在曾经使用此扩展程序的计算机/笔记本电脑/设备上)。

my data.xml is 我的data.xml

<?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 我希望将新注册的用户名和主密码设置为xml格式并写入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. 请注意,如果您尝试在非开发安装中更改那里的任何文件,Chrome会立即认为该扩展已被篡改并永久禁用-它会保存所有文件的加密签名哈希。 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 . 您应该将数据存储在其他存储中:例如chrome.storage If you need to provide a way to export data as a file, you can use chrome.downloads API for it. 如果您需要提供一种将数据导出为文件的方法,则可以使用chrome.downloads API。

Note that Chrome does not provide a safe, encrypted storage accessible from an extension. 请注意,Chrome浏览器提供可从扩展程序访问的安全的加密存储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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