Ajax Step By Step3

第三【.$.getScript()和$.getJSON()】

jQuery 提供了一组用于特定异步加载的方法:$.getScript(),用于加载特定的 JS 文件; $.getJSON(),用于专门加载 JSON 文件。

有时我们希望能够特定的情况再加载 JS 文件,而不是一开始把所有 JS 文件都加载了, 这时课时使用$.getScript()方法。

1.1)点击按钮后再加载 JS 文件

$(‘input‘).click(function()
{
$.getScript(‘test.js‘);
 });

1.2)$.getJSON()方法是专门用于加载 JSON 文件的,使用方法和之前的类似。

$(‘input‘).click(function()
{
 $.getJSON(‘test.json‘,function(response,status, xhr)
{
alert(response[0].url);
 });
 });
时间: 2024-08-05 17:07:22

Ajax Step By Step3的相关文章

Ajax Step By Step1

Ajax 最关键的地方,就是实现异步请求.接受响应及执行回调. jQuery 对 Ajax 做了大量的封装,不需要去考虑浏览器兼容性, 对于封装的方式,jQuery 采用了三层封装:最底层的封装方法为:$.ajax(),而通过这层封装了第二层有三种方法:.load().$.get()和$.post(),最高层是$.getScript()和$.getJSON()方法. 第一.[.load()方法] 参数的使用step by step(load 有三个(URL +data+callback) + 

Ajax Step By Step5

第五.[表单序列化] Ajax 用的最多的地方莫过于表单操作,而传统的表单操作是通过 submit 提交将数据传 输到服务器端.如果使用 Ajax 异步处理的话,我们需要将每个表单元素逐个获取才方能提 交.这样工作效率就大大降低. 对比数据传输的差别: //常规形式的表单提交 $('form input[type=button]').click(function(){ $.ajax({ type:'POST', url:'test.php', data:{ user:$('forminput[n

Ajax Step By Step4

第四,[$.ajax()] $.ajax()是所有 ajax 方法中最底层的方法,所有其他方法都是基于$.ajax()方法的封装.这个方法只有一个参数,传递一个各个功能键值对的对象. $.ajax()方法对象参数表:   参数   类型               说明 url     String          发送请求的地址 type   String        请求方式:POST 或 GET,默认 GET data   Object 或 String  发送到服务器的数据,键值对字

Ajax Step By Step2

第二.[$.get()和$.post()方法] .load()方法是局部方法(有需要父$),因为他需要一个包含元素的 jQuery 对象作为前缀.而$.get()和 $.post()是全局方法,无须指定某个元素. (1)$.get()方法有四个参数,前面三个参数和.load()一样,多了一个第四参数 type,即服务器返回的内容格式:包括 xml.html.script.json.jsonp 和 text.第一个参数为必选参数, 后面三个为可选参数. (1.1)//使用$.get()异步返回 h

Spring Batch_Parallel Steps_使用并行的Step

spring 官方文档:http://docs.spring.io/spring-batch/trunk/reference/html/scalability.html#scalabilityParallelSteps As long as the application logic that needs to be parallelized can be split into distinct responsibilities, and assigned to individual steps

Spring Batch Hello World Example

Spring Batch is a framework for batch processing – execution of a series of jobs. In Spring Batch, A job consists of many steps and each step consists of a READ-PROCESS-WRITE task or single operation task (tasklet). For “READ-PROCESS-WRITE” process,

CodeForces 558 C. Amr and Chemistry && 51NOD 1483 化学变换(暴力 + 贪心)

传送门 Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of ai liters. For this experiment, Amr has to mix all the chemic

Failed to Attach to Process ID Xcode 解决办法

方法1. go to the Product menu and find the Edit Scheme menu there. While in Edit Scheme window, select the "Run" option on the left hand side of the screen and then on the right hand side, change the debugger from LLDB to GDB. 方法2. Step1: ping$ pi

使用索贝尔(Sobel)进行梯度运算时的数学意义和代码实现研究

对于做图像处理的工程师来说,Sobel非常熟悉且常用.但是当我们需要使用Sobel进行梯度运算,且希望得到"数学结果"(作为下一步运算的基础)而不是"图片效果"的时候,就必须深入了解Sobel的知识原理和OpenCV实现的细节(当然我们是OpenCV支持则).这里对具体内容进行研究. 一.基本原理 一般来说,用来表示微分的最常用的算子是索贝尔(Sobel)算子,它可以实现任意阶导数和混合偏导数(例如: ?2/?x?y). 在x方向上用Sobel算子进行近似一阶求导的