我有一个数据变量
var str = [
{"khewat_no":"390","Column1":"ਜਸਮੇਲ ਸਿੰਘ ","owner_share":"36/181"}
,{"khewat_no":"390","Column1":"ਕੌਰ ","owner_share":"22/181"}
]
我想使用 jquery 将此数据保存在具有 .json 扩展名的特定文件位置,请帮助我如何做到这一点
注意:这是您可以将其下载为 JSON 的方式
<!DOCTYPE html>
<html>
<head>
<title>abhi example</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#data").click(function() {
var str = [{
"khewat_no": "390",
"Column1": "ਜਸਮੇਲ ਸਿੰਘ ਪੁੱਤਰ ਸੋਹਣ ਸਿਘ ਪੁੱਤਰ ਕਿਸਨ ਸਿੰਘ vbcrlf ",
"owner_share": "50/151"
}, {
"khewat_no": "390",
"Column1": "ਸੁਖਦੇਵ ਕੌਰ ਪਤਨੀ ਸੋਹਣ ਸਿੰਘ ਪੁੱਤਰ ਕਿਸ਼ਨ ਸਿੰਘ vbcrlf ",
"owner_share": "25/151"
}]
var j_obj = JSON.stringify(str[0]);
$("<a />", {
"download": "data.json",
"href": "data:application/json," + encodeURIComponent(j_obj)
}).appendTo("body")
.click(function() {
$(this).remove()
})[0].click()
})
});
</script>
</head>
<body>
<h1 id="data"> Click to download</h1>
</body>
</html>