ajax返回字符串的比较,该怎么解决
ajax返回字符串的比较
- JScript code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> if(XMLHttp.readyState==4&&XMLHttp.status==200) { var a=XMLHttp.responseText; a=a.replace(/\r\n/g,""); var b="success"; if(a!=b) { document.getElementById("status").innerHTML=a; } else eval("alert('添加成功');window.location='test2.php';"); }
后台页面时echo "success";,返回的是"\r\nsuccess",然后经过正则替换后,成了"success",但是还是和b不相等,怎么回事呀,换成什么字符都是。
------解决方案--------------------
var a=XMLHttp.responseText; 这行下面加上:
alert(a); //弹出什么。贴出来。
------解决方案--------------------
看一下 a和b的length属性是否相同
如果照你说的 alert(a) 弹出的值显示的是 \r\nsuccess
那么它实际的内容应该是
- JScript code
var a = "\\r\\nsuccess"; var b = "success"; <br><font color="#e78608">------解决方案--------------------</font><br>或者你可以用正则匹配来判断: <br> var b=/success/g;<br> if(!b.test(a))<br> {<br> document.getElementById("status").innerHTML=a;<br> }<br> else<br> eval("alert('添加成功');window.location='test2.php';"); <br><font color="#e78608">------解决方案--------------------</font><br>var a=XMLHttp.responseText;<br>alert('[' + a + ']');<br>说说都看到了什么<br><br>只有弄清楚了返回的是什么,才能判断是什么问题<br>瞎猜是没有意义的<br> <div class="clear"> </div>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

alert implements line breaks using the br tag.

The success method in php is used to display a success message. Its usage syntax is "Success('...','Http://www.xxx.com/Admin/User/Index');", when we do not write Url, the system will determine whether there is a previous page. If there is a system, it will jump to the previous page, otherwise it will not jump.

In Laravel, the success method is used to return a successful response in the controller. To use the success method, we need to introduce the Response class in the controller. Then, we can use an instance of this class to call the success method. You can set the response message, the data to be returned, the response status code, and pass these parameters to the success method. A successful response will be returned, which contains the message and user data we set.

This article brings you relevant knowledge about JavaScript. It mainly introduces the differences between var, let and const, as well as the relationship between ECMAScript and JavaScript. Interested friends can take a look at it. I hope Helpful to everyone.

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Audio output and input require specific drivers and services to work as expected on Windows 11. These sometimes end up running into errors in the background, causing audio issues like no audio output, missing audio devices, distorted audio, etc. How to Fix Audio Service Not Responding on Windows 11 We recommend you to start with the fixes mentioned below and work your way through the list until you manage to resolve your issue. The audio service may become unresponsive for a number of reasons on Windows 11. This list will help you verify and fix most issues that prevent audio services from responding on Windows 11. Please follow the relevant sections below to help you through the process. Method 1: Restart the audio service. You may encounter

The role and examples of var keyword in PHP In PHP, the var keyword is used to declare a variable. In previous PHP versions, using the var keyword was the idiomatic way to declare member variables, but its use is no longer recommended. However, in some cases, the var keyword is still used. The var keyword is mainly used to declare a local variable, and the variable will automatically be marked as local scope. This means that the variable is only visible within the current block of code and cannot be accessed in other functions or blocks of code. Use var

The reason for the error message indicates that in the python code, an object (represented by the self variable) is used, but the object does not have an attribute named k. This may be because the object does not have this property defined, or a type error in the code causes the object to not be of the expected type. How to Fix To resolve this error, you may need to do one or more of the following: Check your code for the error and make sure the object referenced by the self variable has a property named k. Check your code for type errors and make sure the object referenced by the self variable is of the expected type. If the attribute is missing, you need to define this attribute in the class and use tryexcept to get this error. If you are sure that k is an attribute that is not defined in the class, please confirm
