[英]Call Second Function in a Scriptfile
var CustomerBoxesLoad = function () {
var handleAjaxBoxesSelectedCountry = function() {
$.ajax({
type: "POST",
url: 'ajax/selectbox/country_selected.php',
dataType:'json',
success: function(data) {
var select = $("#countryCodeBox"), options = '';
select.empty();
options += "<option value='0'>Select ...</option>";
for(var i=0;i<data.length; i++)
{
options += "<option value='"+data[i].id+"'>"+ data[i].name +"</option>";
}
select.append(options);
}
});
}
var handleAjaxBoxesCustomerType = function() {
$.ajax({
type: "POST",
url: 'ajax/selectbox/customer_type.php',
dataType:'json',
success: function(data) {
var select = $("#customerTypeBox"), options = '';
select.empty();
options += "<option value='0'>Select ...</option>";
for(var i=0;i<data.length; i++)
{
options += "<option value='"+data[i].id+"'>"+ data[i].name +"</option>";
}
select.append(options);
}
});
}
return {
//main function to initiate the module
init: function () {
handleAjaxBoxesSelectedCountry();
handleAjaxBoxesCustomerType();
}
};
}();
I have a function calling from a PHP file. 我有一个从PHP文件调用的函数。 At the end of the PHP file i am calling the Ajax function: 在PHP文件的末尾,我正在调用Ajax函数:
jQuery(document).ready(function() {
CustomerBoxesLoad.init();
});
All the Ajax select boxes filling works good. 所有的Ajax选择框填充效果都很好。 Now i want to trigger the Ajax script from a (a href="") tag. 现在,我想从(a href =“”)标记触发Ajax脚本。 But the function will not trigger like this: 但是该函数不会像这样触发:
a href="javascript:handleAjaxBoxesSelectedCountry();">Refresh Select Box
THIS reference to the JavaScript dont work!! 此对JavaScript的引用不起作用!
add another function to your return: 在返回中添加另一个函数:
return {
//main function to initiate the module
init: function () {
handleAjaxBoxesSelectedCountry();
handleAjaxBoxesCustomerType();
}
handleAjaxBoxesSelectedCountry: function () {
handleAjaxBoxesSelectedCountry();
}
};
and the 'a' tag: 和'a'标签:
<a href="javascript:CustomerBoxesLoad().init();return false;">STH</a>
I solved it myself: 我自己解决了:
return {
//main function to initiate the module
init: function () {
handleAjaxBoxesCountry();
handleAjaxBoxesCustomerType();
},
init_country: function () {
handleAjaxBoxesCountry();
},
init_type: function () {
handleAjaxBoxesCustomerType();
}
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.