警报文本从文件JQuery / javascript

Alert text from file JQuery / javascript

本文关键字:JQuery javascript 文件 报文 文本      更新时间:2023-09-26

我不能得到这些简单的事情的工作,我有一个文本文件中有一些文本,我想要一个警报包含文本文件内的文本被触发时,点击"btn/链接"。

我还希望能够比较,看看文件中的文本是真还是假:

<<p> JSFIDDLE演示/strong> HTML:

<div id="alert_btn"><a href="javascript:alert_fn();">click_me</a></div>
JQuery/javascript:

function alert_fn(){
    $.get('http://www.patan77.com/example_test.txt', function(data) {
        alert(data);
        if (data == true){
            alert("true");
        }else{
            alert("false");
        }
    });   
}

我想我已经修好了。

Test_DEMO

HTML with jQuery/Javascript

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="1" />
<title>Test_Alert</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
function alert_fn(){
    $.get('http://www.patan77.com/example_test.txt', function(data) {
       alert(data);
    });   
}

function alert_fn_2(){
    $.get('http://www.patan77.com/example_test.txt', function(data) {
        var text_file = data;
        if (text_file == "hello world"){
            alert ("its true");
        }else{
            alert ("its false");
        }
    });
}
</script>
</head>
<body>
<div id="alert_btn"><a href="javascript:alert_fn();">click_me</a></div>
<div id="alert_btn_2"><a href="javascript:alert_fn_2();">click_me_to_see_if_true</a></div>
v.06
</body>
</html>