Jquery和HTML5来搜索JSON

Jquery和HTML5来搜索JSON

本文介绍了Jquery和HTML5来搜索JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将JSON文件ftp://mysite.com/json1.json存储在我的根服务器文件夹中。

这应该意味着http://www.mysite.com /json1.json是真的吗?



我试图用搜索框找到第一个:thefirstname然后打印出其余的。



我在最后三个文本框中没有得到任何内容。



I have stored the JSON file "ftp://mysite.com/json1.json" in my root server folder.
This should mean that "http://www.mysite.com/json1.json" holds true?

I am trying to use the search box to find the first:"thefirstname" and then printout the rest.

I am not getting anything in the last three text boxes.

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.1.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        function process() {
        	$.getJSON("http://www.mysite.com/json1.json"){
        		$each(function(key,val){
        			if ($("#text1").val()="thefirstname" && key="first"){
	        	            $("#firstname").val(key.first);
		                    $("#lastname").val(key.last);
		                    $("#description").val(key.desc);
			         }
			});
	      	});
        }
    </script>
      <form name="myform" action="jQueryJson.htm">
	    <input type="text" name="text1" value="thefirstname" size="30" />                    <tr><td align="center" colspan="3">
<input type="button" name="search" value="Search for FirstName" size="50" onclick="process" /></td><td align="center"></td><td align="center">
</td></tr>
<input type="text" name="firstname" value="" size="4"/></td><td align="center">
<input type="text" name="lastname" value="" size="4"/></td><td align="center">
<input type="text" name="description" value="" size="4"/>
	</form>







json1.json
[
	{"first":"fgdfb", last":"dfghdfgh", "desc":"jjif"},
	{"first":"jdtyhjn", last":"hmbnmgh", "desc":"hfhhfyif"},
	{"first":"fgbnfgjthj", last":"tewgsdfgngh", "desc":"argrayif"},
	{"first":"kuykyky", last":"bfbffc", "desc":"lykghif"},
	{"first":"thefirstname", last":"dsfhngh", "desc":"pgkkgff"},
	{"first":"ghjjhb", last":"fdasfgh", "desc":"nfhdfhjif"},
	{"first":"ohhklhjb", last":"qsdwdgh", "desc":"vfrfeif"}
]





我尝试过:



尝试使用按钮,但这更简单。



What I have tried:

Tried using a button but this was more straightforward.

推荐答案




这篇关于Jquery和HTML5来搜索JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 16:58