Ajax : $. get()和$.post() $.getScript $.getJSON
2024-10-01 18:14:40
<body>
<input type="button" value="Ajax" />
<div id="box"></div>
</body>
test.html
<span class="name">党兴明</span>
<span class="age">24</span>
test.php
<?php // if($_POST['age'] == 24){
// echo 'php:党兴明24';
// }else{
// echo '木有';
// } if($_GET['age'] == 24){
echo 'php:党兴明24';
}else{
echo '木有';
} ?>
test.xml
<?xml version="1.0"?>
<root>
<url>www.ycku.com</url>
</root>
test.josn
[
{
"url" : "www.ycku.com"
}
]
$. get():
//1 三种传值
$('input').click(function(){
$.get('test.php?age=24',function(response,status,xhr){
$('#box').html(response);
});
});
//2
$('input').click(function(){
$.get('test.php','age=24',function(response,status,xhr){
$('#box').html(response);
});
});
//
$('input').click(function(){
$.get('test.php',{
age:24
},function(response,status,xhr){
$('#box').html(response);
});
});
$.post()
//1 两种传值
$('input').click(function(){
$.post('test.php','age=24',function(response,status,xhr){
$('#box').html(response);
});
});
//
$('input').click(function(){
$.post('test.php',{
age:24
},function(response,status,xhr){
$('#box').html(response);
});
});
读取.xml和.josn文件:
$('input').click(function(){
$.post('test.xml',function(response,status,xhr){
$('#box').html($(response).find('root').find('url').text());
});
}); $('input').click(function(){
$.post('test.json',function(response,status,xhr){
$('#box').html(response[0].url);
});
});
$.getScript()
$('input').click(function(){
$.getScript('js/test.js');
});
$.getJSON()
$('input').click(function(){
$.getJSON('test.json',function(response,status,xhr){
$('#box').html(response[0].url);
});
});
最新文章
- 【Centos】修改网卡名字&;随之出现的问题
- ThoughtWorks代码挑战——FizzBuzzWhizz
- Leetcode: Sort Transformed Array
- 我眼中的WebViewJavascriptBridge
- MS SQL Server 2008 R2 常规操作
- JavaScript变量声明var,let.const
- mysql之外键
- tensorflow-gpu安装的一些注意
- 潭州课堂25班:Ph201805201 django 项目 第九课 图片验证码前台实现,判断用户是否注册功能实现 (课堂笔记)
- 由于php环境时间与北京时间相差7个小时
- GRU
- 在JavaScript里写类层次结构?别那么做!
- Codeforces 395 D.Pair of Numbers
- laravel中form表单,ajax传值没反应
- vue打包后运行在本地/非服务器端环境的访问路径
- android回调函数
- hdu5739
- ImageSwitch图像切换控件
- #include ";*.c";文件的妙用
- wewe