Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check sensitive words before submitting articles in ajax

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how ajax implements the review of sensitive words before submitting the article, which is very detailed and has a certain reference value. Friends who are interested must read it!

So I thought of returning the Boolean value passed by Ajax on submission. In fact, the function get2 () passed by Ajax is a subfunction of chkfull (bt) and cannot be passed to an external function, and alert () does not work. So simply cancel the submit type of the submit button and use Javascript to automatically submit the form after a series of checks.

The code is as follows

HTML

The code is as follows:

/ / Note the type is "button"

/ / embed a hidden text box to pass a value to Ajax

The Javascript part of Ajax

The code is as follows:

Function chkfull (bt) {

Var content = document.getElementById ("usercontent") .value

If (content== "")

{

Alert ("text is required.") / / determine whether the content of the article is empty

Return false

}

Else

{

Var xHRObject=false

If (window.XMLHttpRequest) / / judge the browser kernel

{

XHRObject=new XMLHttpRequest ()

}

Else if (window.ActiveXObject)

{

XHRObject= new ActiveXObject ("Microsoft.XMLHTTP")

}

Function get2 () / / defines the get2 function to prepare for onreadystatechange. This function cannot be placed after xHRObject.onreadystatechange=get2;

{

If (xHRObject.readyState==4 & & xHRObject.status==200)

{

Var serverText=xHRObject.responseText

If (serverText== "sense")

{

If (confirm ("are you sure you want to publish your article with sensitive words?\ n\ r [Yes, publish] will be reviewed, please wait.\ n\ r [No, do not publish] will return to the interface, please modify the words.")

{

Bt.value= "submitting"

Bt.disabled=true;// close button

Document.getElementById ("userchksense") .value = "sense"; / / change the value of userchksense to sense, so that post to add.php can directly check whether to lock the article without having to check the article again.

Document.form1.submit (); / / submit the form

}

Else// seems a little redundant, but it's safer this way.

Return false

}

Else

{

Bt.value= "submitting"

Bt.disabled=true

Document.getElementById ("userchksense") .value = "nonsense"

Document.form1.submit ()

}

}

}

Var title=document.getElementById ("usertitle"). Value

Var tag=document.getElementById ("usertag"). Value

Var intro=document.getElementById ("userintro"). Value

Var content=document.getElementById ("usercontent"). Value

Var v = "title=" + title+ "& tag=" + tag+ "& intro=" + intro+ "& content=" + content

XHRObject.open ("POST", ".. / ajax/ajax.php", true)

XHRObject.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded")

XHRObject.onreadystatechange=get2;// the get2 here cannot be parenthesized, otherwise the return value of the function is assigned to a variable instead of the function itself to xHRObject.onreadystatechange (Note 1)

XHRObject.send (v)

}

}

The above is all the contents of the article "how to review sensitive words before submitting articles by ajax". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report