[英]Jquery calling function after ajax load fails
We have an external javascript file that gets called as part of a catalog results page, AJAX is involved on this document - https://www.columnradiators4u.co.uk/uk/classic-white-column-radiators.html 我们有一个外部javascript文件,该文件被称为目录结果页面的一部分,此文档涉及AJAX- https://www.columnradiators4u.co.uk/uk/classic-white-column-radiators.html
I have a jquery function for altering colour of a span when it detects certain text - please see my code below. 我有一个jquery函数,用于在检测到某些文本时更改跨度的颜色-请参阅下面的代码。
function ReInitStockColor(){
$(function() {
$("span:contains(In Stock)").css("font-weight", "bold").css("color", "#00BF00");
$("span:contains(Due)").css("color", "#FF0000");
$("span:contains(Made)").css("font-weight", "bold").css("color", "#00BF00");
});
}
This code is being called earlier on in our file, however it is not executing. 此代码已在我们的文件中更早地调用,但是未执行。 If I take my code in to chrome/Firefox console and run it, it executes successfully.
如果我将代码带入chrome / Firefox控制台并运行它,它将成功执行。
Is anybody able to assist in this matter? 有人可以协助处理此事吗?
EDIT: Full JS file here: https://jsfiddle.net/8z8oq2sm/ EDIT 08/01: Anybody able to offer any further help? 编辑:完整的JS文件在这里: https ://jsfiddle.net/8z8oq2sm/编辑08/01:有人能够提供任何进一步的帮助吗? I've tried the suggestions below to no avail.
我尝试了以下建议,但无济于事。
$(function() { ... });
is just jQuery short-hand for 只是jQuery的简写
$(document).ready(function() { ... });
$(function() { ... }); $(function(){...}); suggests that code will be executed only on document ready.
建议仅在准备好文档时执行代码。 And you have it inside function ReInitStockColor.
您可以在函数ReInitStockColor中使用它。 Can you remove that $(function() { ... }) thing and see if this ReInitStockColor function is being called?
您可以删除该$(function(){...})东西,看看是否正在调用此ReInitStockColor函数吗?
您应该在AJAX 成功或完成函数中调用此ReInitStockColor()
函数
you need this? 你需要这个?
$.ajaxSetup({
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.