jQuery- use ajax() in jquery instead of traditional json to pass values


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>json pass value test</title>
<style>
td{
	background:#066;}
</style>
</head>

<body>
<table border="1" id="name">
		
</table>
    <button id="test" value="test" type="button">test</button>
    
   <script src="jquery.js" type="text/javascript"></script>
    <script>
	 /* Traditional json pass value
    	$(function(){
			$("#test").click (function(){
				$.getJSON('tablejsontest.json',function(data){
					$('#name').empty();
					var html = '';
					$.each(data,function(nameIndex,name){
						html +='<tr><td>' + name['name'] + '</td><td >' + name['sex'] + '</td><td>' + name['school'] + '</td></tr>';
						})
						$('#name').html(html);
					})
				})
			})
			*/
			
			
			 //json pass value in ajax
			$(function(){
				$('#text').click (function(){
					$.ajax({
						type:"GET",
						url:"tablejsontest.json",
						dataType:"json",
						success:function(data){
							$('#name').empty();
							var html ='';
							$.each(data,function(nameIndex,name){
						html +='<tr><td>' + name['name'] + '</td><td >' + name['sex'] + '</td><td>' + name['school'] + '</td></tr>';
						});
						$('#name').html(html);
						}
						});
					});
				})
    </script>
</body>
</html>


The tablejsontest.json code is as follows:

[
	{
		"name":"anna",
		 "sex":" ",
		 "school":"The First Middle School"
		},
	
	{
		"name":"jon",
		"sex":"man",
		 "school":"The Third Middle School"
		}
	
	
]


Intelligent Recommendation

jquery ajax post pass an array of multiple checkbox values

jquery ajax post pass an array of multiple checkbox values Use $ .each (function () {}); the corresponding values ​​obtained checkbox, The traditional need to be set to true when ajax upload     ...

Use Json to pass a single value in jquery

Result graph: One, Action class Two, configure Struts Three, pass jqury on the html page to obtain a single value...

Ajax and jQuery - use $ .get () and $ .post () method to pass HTML, XML, JSON data

HTML format data XML format data JSON format data...

AJAX Basics: Use of the Ajax method packaged in jQuery (Key: Pass JSON Type Data - Avoid the default format conversion of the AJAX method)

Ajax is a frequently used technique, in addition to the self-encapsulation, JQuery also encapsulates Ajax, so the AJAX method encapsulated by jQuery is first defined from jQuery, naturally to introduc...

Jquery ajax traditional parameter explanation

The ajax parameter of the jquery framework is in addition to the usual There is also a parameter that needs special attention.traditionalThe default is false. When ajax does data processing, it is pas...

More Recommendation

The role of the traditional parameters of jQuery ajax

In ajax parameter passing in string delimiter spread apart to the background, and then split in the background. This led to arguments passed can not contain a comma, the security implications of the p...

SpringBoot and Jquery implement ajax to pass json strings and echo messages (practice)

Scenes inspinia front-end page template+thymeleaf template+jquery+springboot Click Submit to transmit the id of the currently selected row to the backend as a json string, and the backend will impleme...

How to use Jquery+ajax+springMVC to return json

JSP page: Background control class: These two sentences must be added to return the json value...

JQuery works with Ajax and JSON

JSON (JavaScript Object Notation) is a simple data format that is lighter than xml. JSON is a JavaScript native format, which means that no special APIs or toolkits are required to process JSON data i...

cakephp jquery ajax json

Introduction JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy for people to read and write. Cakephp 1.2 provides built-in support for JSON, mainly in two special ways: Rou...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top