Chrome: Uncaught TypeError: Cannot read property 'replace' of undefined

房东的猫 提交于 2019-12-25 01:55:19

问题


I am trying to write a code to auto select a radio button:

<input type="radio" class="pricezone-radio-input" 
name="abcdef" value="123" checked="" title="A">

Since the name of the radio button changes every time when the website refresh, so I used the title instead

var $ = window.jQuery;
(function() {
'use strict';

// Your code here...
$("[A']").click();
})();

When I look at the console in chrome, after the code run, an error occur:

common.js?version=1552060637712:1175 Uncaught TypeError: Cannot read 
property 'replace' of undefined
at handleAjaxError (common.js?version=1552060637712:1175)
at Object.success (performanceDetail.js?version=1552060637712:345)
at u (userscript.html?id=8cad0fd6-8836-407e-b409-3f083400471d:5)
at Object.fireWith [as resolveWith] (userscript.html?id=8cad0fd6-8836-407e- 
b409-3f083400471d:5)
at k (userscript.html?id=8cad0fd6-8836-407e-b409-3f083400471d:5)
at XMLHttpRequest.eval (userscript.html?id=8cad0fd6-8836-407e-b409- 
3f083400471d:5)

Can anyone suggest how can I fix this?


Just find that it is the script of the website itself causing the problem

handleAjaxError = function(ajaxData){
    var metaTag = $(ajaxData).filter("meta[http-equiv=refresh]");
    if (typeof(metaTag) !== undefined) {
        var content = metaTag.attr("content");
        var url = content.replace("0; url=", "");
        window.location.href = url;
    } else {
        $('#loading-blk').hide('hidden');
        $('.ajax-call-error').removeClass('hidden');
    }
};

is there any way I can solve this?


Chrome: Version 72.0.3626.121; Tampermonkey: v4.8

The exact script I'm using:

// ==UserScript==
// @name         New test
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://ticket.urbtix.hk/internet/zh_TW/secure/event/37954/performanceDetail/367999
// @require http://code.jquery.com/jquery-3.3.1.min.js
// @grant        none
// ==/UserScript==

var $ = window.jQuery;


(function() {
    'use strict';

    // Your code here...
    $("[title='Price Zone B']").click();

})();

来源:https://stackoverflow.com/questions/55120305/chrome-uncaught-typeerror-cannot-read-property-replace-of-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!