jQuery的AJAX调用后执行脚本

编程入门 行业动态 更新时间:2024-10-23 18:34:59
本文介绍了jQuery的AJAX调用后执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我加载某些HTML code与.load功能自动对焦jQuery的一个div包含一些code我想执行;

I load some HTML code into a div with the .load function af jQuery that contains some code I want to execute;

$.ajax({ type: "GET", url: url, dataType: "html", success: function(data){ //..... } });

加载Ajax请求的警报后();功能的工作原理,但在someFunction不会。

After loading the ajax request the alert(); function works, but the the someFunction won't.

$(document).ready(function(){ alert('TEST'); //this works someFunction("#debug",'var');//this doesn't });

我如何从一个Ajax调用执行此功能

How can I execute this function from an Ajax call

一个为&LT执行功能;一的onclick =someFunction()也不行

推荐答案

也许你应该使用 jQuery.getScript 来装载从服务器一些JavaScript并执行它。

Probably you should use jQuery.getScript to loading some javascript from the server and execute it.

更新: 在大多数情况下,一个负载仅就 jQuery.ajax 的纯HTML片段。元素结合到一些JavaScript函数之一做成功里面处理。所有的功能这在以前(装载任何事件处理一一使用<脚本> 在< HEAD> 主网页(其中要求在网页上的块) jQuery.ajax )。然后,所有看起来并不需要非常清晰,动态加载的任何脚本。

UPDATED: In the most cases one load only the pure HTML fragment with respect of jQuery.ajax. Binding of elements to some javascript functions one do inside of success handle. All functions which one use in any event handler one loaded before (with <script> in the <head> block) on the main page (on the page which call jQuery.ajax). Then all look very clear and dynamic loading of any scripts is not needed.

更多推荐

jQuery的AJAX调用后执行脚本

本文发布于:2023-10-31 07:27:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1545429.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   jQuery   AJAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!