jQuery的AJAX调用后执行脚本 [英] executing script after jQuery Ajax Call

查看:212
本文介绍了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调用后执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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