当加载通过AJAX的HTML页面,将脚本标记加载? [英] When loading an html page via ajax, will script tags be loaded?

查看:134
本文介绍了当加载通过AJAX的HTML页面,将脚本标记加载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你使用AJAX加载HTML文档,这是什么的HEAD标签内的节点做到:(文字,链接,风格,元,标题)不理会他们,或加载和分析呢? 而在jQuery的的阿贾克斯()函数的情况?

When you load an html document using AJAX, what does it do with the nodes inside the HEAD tag: (script,link,style,meta,title) ignore them or load and parse them? And in the case of jquery 's ajax() function?

推荐答案

在调用 jQuery的。阿贾克斯() 的方法,你可以指定的dataType 属性,它描述了什么样的数据,你从服务器期望,和如何一旦收到处理它。

When you call the jQuery.ajax() method, you can specify the dataType property, which describes what kind of data you are expecting from the server, and how to handle it once it is received.

在默认情况下,jQuery将尝试的dataType 基于MIME类型响应的猜测。然而,你可以明确地从下面的指定数据类型:

By default, jQuery will try to guess the dataType based on the MIME type of the response. However you can explicitly specify a dataType from the following:

  • HTML :返回HTML纯文本;当DOM中插入包含脚本标记进行评估。

  • html: Returns HTML as plain text; included script tags are evaluated when inserted in the DOM.

文本:纯文本字符串

XML :返回一个可以通过jQuery处理XML文档

xml: Returns a XML document that can be processed via jQuery.

剧本:评估响应JavaScript和返回纯文本。禁用缓存,除非选择高速缓存被使用。

script: Evaluates the response as JavaScript and returns it as plain text. Disables caching unless option "cache" is used.

JSON :评估响应的JSON,并返回一个JavaScript对象。

json: Evaluates the response as JSON and returns a JavaScript object.

JSONP :使用JSONP的JSON块负荷。将增加一个额外的?回调=?你的URL指定回调的结束。

jsonp: Loads in a JSON block using JSONP. Will add an extra "?callback=?" to the end of your URL to specify the callback.

作为一个例子,下面的AJAX调用将返回数据作为纯文本字符串,不执行脚本或操纵DOM:

As an example, the following ajax call will return the data as a plain text string, without executing the scripts or manipulating the DOM:

$.ajax({
  url: 'ajax/test.html',
  dataType: 'text',
  success: function(data) {
    alert(data);
  }
});

这篇关于当加载通过AJAX的HTML页面,将脚本标记加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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