仅当字符串匹配数据时如何发送请求

How to send Request only if string matches data

我希望我的脚本从事件数据中读取 "ident" 以及它是否与特定字符串匹配。如果 "ident" 与特定字符串不匹配,则在控制台打印 "hello" 或类似的内容。发送 post 请求。

下面是示例中打印的一些数据。 https://pastebin.com/ZMck0WsM

var evtSource = new EventSource("http://colorillo.com/_watch//_index?_=1559553617984");

evtSource.onmessage = function(e) {
var obj = JSON.parse(e.data);
var line = JSON.stringify(obj.line)

$.post("/draw.php?ing=_index", {
                l: (line),
                w: ("30"),
                c: ("#ffffff"),
                o: ("100"),
                f: ("1"),
                _: ("false")
            })
}
if (obj.ident === "foo")
{
    console.log("hello")
}
else
{
    // Send post request...
} 

尝试一下,如果以下内容有帮助

var match = ident.match(/[a-z]/); //remember to put the patten of what you want to match
if(match){
  console.log(match)
}else{
 //send post request
}