从ajax调用返回的html调用jquery插件函数

时间:2021-08-13 23:58:49

Can anyone tell me, can I invoke third party jquery funcation from html return by ajax call please ?

任何人都可以告诉我,我可以通过ajax调用从html返回调用第三方jquery函数吗?

The problem I am facing is, there is an ajax call, returning some chunk of html (html for jquery datatable). In this html there is one link to add a new row to the table when clicked. To add this new row dynamically I am calling jquery data table's fnOpen() function, but it's not working. If I don't use ajax call and write html by myself it works properly. The jquery datatable script is at client side, it's not being returned as part of an ajax call.

我面临的问题是,有一个ajax调用,返回一些html(html用于jquery数据表)。在这个html中,有一个链接可以在单击时向表中添加新行。要动态添加这个新行,我正在调用jquery数据表的fnOpen()函数,但它不起作用。如果我不使用ajax调用并自己编写html它可以正常工作。 jquery数据表脚本位于客户端,它不会作为ajax调用的一部分返回。

Any help is appreciated.

任何帮助表示赞赏。

Thank you
Arya

谢谢Arya

1 个解决方案

#1


0  

I've run into a similar issue before. Difficult to diagnose exactly with no code example though.

我之前遇到过类似的问题。但是,没有代码示例很难准确诊断。

This is probably happening because the link (which I'm assuming is just an object you're assigning an onClick even to?) has not been loaded before you are assigning this click event.

这可能是因为在分配此单击事件之前,链接(我假设的只是您正在分配onClick甚至是?的对象)尚未加载。

Try assigning the click event to the link object after the ajax call has completed. This should solve you're problem.

在ajax调用完成后,尝试将click事件分配给链接对象。这应该可以解决你的问题。

so it would be something like:

所以它会是这样的:

//ajax call
$.get(somepage,function(data){
    //do some formating of data and probably insert into html?
    //once new links have been inserted into html, assign click event.
    $(".linkClass").click(function(){fnOpen()});
});

#1


0  

I've run into a similar issue before. Difficult to diagnose exactly with no code example though.

我之前遇到过类似的问题。但是,没有代码示例很难准确诊断。

This is probably happening because the link (which I'm assuming is just an object you're assigning an onClick even to?) has not been loaded before you are assigning this click event.

这可能是因为在分配此单击事件之前,链接(我假设的只是您正在分配onClick甚至是?的对象)尚未加载。

Try assigning the click event to the link object after the ajax call has completed. This should solve you're problem.

在ajax调用完成后,尝试将click事件分配给链接对象。这应该可以解决你的问题。

so it would be something like:

所以它会是这样的:

//ajax call
$.get(somepage,function(data){
    //do some formating of data and probably insert into html?
    //once new links have been inserted into html, assign click event.
    $(".linkClass").click(function(){fnOpen()});
});