更改JSON文件的来源,而无需重新加载页面? [英] Change the source of a JSON file, without reloading the page?

查看:92
本文介绍了更改JSON文件的来源,而无需重新加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,如何在用户提交表单时更改json数据的src?我需要将src的'text ='部分更改为用户在表单中输入的内容,而不重新加载页面。

< script> 
函数myFunction(arr){

var i = 0;
document.getElementById(fullname)。innerHTML = arr [i] .FULLNAME;
document.getElementById(motto)。innerHTML ='+ arr [i] .MOTTO +';
...
...
document.getElementById(firstlog)。innerHTML = arr [i] .FIRSTLOGIN;
document.getElementById(lastact)。innerHTML = arr [i] .LASTACTIVITY;
}
});
< / script>
< script src =http://nsdata.a78.org/m/json.php?text=southern_ageena&type=json>< / script>

解决方案

JQuery的parseJSON [ ^ ]例如,简单地将json对象评估为javascript对象。所以你要做的就是对该URL进行ajax调用,并将结果传递给这个方法。

或者,有一个 getJSON [ ^ ] ...

I have the following code, how can I get the src of the json data to change when the user submits a form? I need to change the 'text=' part of the src, to what the user has entered in the form, without a page reload.

<script>
function myFunction(arr) {
	
        var i =0;
        document.getElementById("fullname").innerHTML =  arr[i].FULLNAME ;
        document.getElementById("motto").innerHTML =  "'"+arr[i].MOTTO+"'";
        ...
        ...
        document.getElementById("firstlog").innerHTML = arr[i].FIRSTLOGIN;
        document.getElementById("lastact").innerHTML = arr[i].LASTACTIVITY;
		}
});
</script>
<script src="http://nsdata.a78.org/m/json.php?text=southern_ageena&type=json"></script>

解决方案

JQuery's parseJSON[^] for example simply evaluates the json object to javascript object. So all you have to do is make an ajax call to that url, and pass the result to this method.
Or, there is getJSON[^]...


这篇关于更改JSON文件的来源,而无需重新加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆