调用内从一个AJAX调用HTML返回一个jQuery功能 [英] Calling a jQuery function inside html return from an AJAX call
问题描述
我的工作就是使用jQuery在网页上。我有一个Ajax调用,获取数据从服务器和更新一个div。内的数据有一个jQuery功能,但后的数据被加载到页的功能没有被调用。我已经包括在已经在页面适当的js文件。
I am working on a web page that is using jQuery. I have an Ajax call that gets data from the server and updates a div. Inside that data there is a jQuery function, but the function is not being called after the data is loaded into the page. I have the proper js files included in the page already.
这是从Ajax调用返回,并放置到一个div:
This is what is returned from the Ajax call and placed into a div:
<script type="text/javascript">
$(function() {
$('input').myFunction('param');
});
</script>
<p> other html </p>
我如何得到返回的JavaScript的HTML后运行插入网页?
How do I get the returned javascript to run after the html is inserted into the page?
(我用Rails与jRails插件)
(I am using Rails with the jRails plugin )
推荐答案
如果您希望JavaScript代码的评估,与HTML内容,你应该设置AJAX调用的数据类型选择HTML:
If you want JavaScript tag evaluation, with html content, you should set the dataType option of the ajax call to "html":
$.ajax({
type: "GET",
url: "yourPage.htm",
dataType: "html"
});
或数据类型脚本,如果要加载和执行.js文件:
Or dataType "script", if you want to load and execute a .js file:
$.ajax({
type: "GET",
url: "test.js",
dataType: "script"
});
下面的详细信息:的Ajax / jQuery.ajax
这篇关于调用内从一个AJAX调用HTML返回一个jQuery功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!