无法在 VBScript 中的 xmlhttp 响应文本上使用任何字符串函数
除了将其打印到屏幕上之外,我无法对以下代码中的响应文本执行任何操作。我想使用 if 语句来检查响应文本是什么,但每当我尝试这样做时,它都不会打印任何内容。
对于此示例,假设响应文本为“2”
代码:
Set xmlhttp = server.CreateObject("MSXML2.XMLHTTP")
xmlhttp.open "POST", url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml"
message = "test example"
xmlhttp.send(message)
if xmlhttp.responseText = "2"
response.Write("Found a 2")
end if
发生的情况是,如果我只有 response.Write(xmlhttp.responseText) ,它将打印出这两个文本,但是当我尝试在响应文本它会忽略它并且不打印任何内容
感谢任何帮助
I can't do anything with the response text from the below code other than print it to the screen. I want to use an if statement to check what the response text is,but whenever I try this it prints nothing.
For the sake of this example, assume the response text is "2"
Code:
Set xmlhttp = server.CreateObject("MSXML2.XMLHTTP")
xmlhttp.open "POST", url,false
xmlhttp.setRequestHeader "Content-Type", "text/xml"
message = "test example"
xmlhttp.send(message)
if xmlhttp.responseText = "2"
response.Write("Found a 2")
end if
What's happening is if I just have response.Write(xmlhttp.responseText) it will print out the two, but when I try and do any string functions on the response text it ignores it and prints nothing
Any help appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
responseText 向您发送一个字符串值“<”return>2<”/return>,但是当您打印该值时,它非常智能,因此只会打印 2。因此,当您与“2”进行比较时,它不匹配。
我通过 search() 方法解决了这个问题。
例如...
var response = xmlhttp.responseText;
var 找到 = response.search("2");
如果(找到!= -1)
{
alert("发现了2");
解释
:如果在 string1 中找不到 string2,则 string1.search(string2) 方法发送 -1。但如果找到它会向您发送第一个找到的位置。因此,如果结果不是-1,则可以肯定在string1中找到了string2。你可以用这种方式尝试。我认为你可以解决你的问题。祝你好运。
responseText send you a string value "<"return>2<"/return> but when you print this value it is very intelegent so that only 2 will be printed. so when you compare with "2" it does not match.
I solved this problem by search() method.
for example....
var response = xmlhttp.responseText;
var found = response.search("2");
if(found != -1)
{
alert ( "Found a 2" );
}
explanation: this string1.search(string2) method send -1 if string2 is not found in string1. but if found it send you the position of first found. so if the result is not -1 then it is sure that it string2 is found in string1. you can try in this way. i think you can solve your problem. best of luck.