请教个AJAX问题
- JScript code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> function nums(){ var n = document.natform.num.value; var url="index.php?c=nat&a=natid&id="+n+""; if(n == ''){ document.getElementById('num').style.display='block'; document.getElementById('num').innerHTML='编号不能为空'; document.getElementById('num').style.color='red'; return false; }else{ xmlHttpRequest = createXmlHttpRequest(); xmlHttpRequest.onreadystatechange = handle; xmlHttpRequest.open("GET",url,true); xmlHttpRequest.send(null); //我的问题就是 在这个else里怎么接收到 handle()的返回值(true false) } } function handle(){ if(xmlHttpRequest.readyState == 4){ var re = xmlHttpRequest.responseText; if(re){ document.getElementById('num').style.display='block'; document.getElementById('num').innerHTML='编号已存在'; document.getElementById('num').style.color='red'; return false; }else{ document.getElementById('num').style.display='block'; document.getElementById('num').innerHTML='可以使用'; document.getElementById('num').style.color='green'; return true; } } }
以上是一个ajax 判断 id 是否存在的, 如果不存在,可以提交,如果存在提示已存在,不能提交
- JScript code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> function saves(){ if(nums()){ document.natform.action="index.php?c=nat&a=addnatpost"; document.natform.submit(); } }
但是现在问题是 num() 接收不到 handle() 的返回值, 所以已存在的时候 num() 状态是未定义的, 请教下这块怎么改
------解决方案--------------------
- JScript code
var re = xmlHttpRequest.responseText; //这里的re值是多少?alert看看。 //如果没有值,说明是后端接收处理的问题 <br><font color="#e78608">------解决方案--------------------</font><br> ajax 是异步通讯方式,所以你不可能从 num() 得到正确的返回值<br>你所需要的提交动作应在 handle 中完成 <div class="clear"> </div>

On September 3, version 1.5 of the Grand Theft Auto VI document which provides a detailed overview of everything that is known about the game to date. The updated version of the document was announced in a trailer published on X (formerly Twitter).??

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

document.cookie获取不到的解决办法:1、浏览器的隐私设置;2、Same-origin policy;3、HTTPOnly Cookie;4、JavaScript代码错误;5、Cookie不存在或过期;6、跨域问题;7、查看器模式;8、服务器问题;9、JavaScript执行时机;10、检查 console log等。

getElementById可以通过元素的id属性获取对应的HTML元素,进而方便地对其进行操作和修改。无论是动态地改变元素的内容、样式或者是添加事件监听器,getElementById都是一个非常常用的方法 。

JavaScript中Document对象介绍及代码示例引言:在JavaScript中,Document对象是代表整个HTML文档的接口,它提供了对HTML文档的访问和操作方法。本文将介绍Document对象的常用方法和属性,并提供一些具体的代码示例。getElementById方法getElementById是Document对象的一个重要方法,用于根据指

常见的document属性和方法:属性:1、document.title:获取或设置文档的标题,通常显示在浏览器的标题栏或标签上;2、document.URL:获取文档的完整URL;3、document.documentElement:获取文档的根元素,通常是<html>元素;4、document.body:获取文档的<body>元素;5、document.head等等。

先给出网页地址:https://wall.alphacoders.com/featured.php?lang=Chinese主要步骤:利用Jsoup的connect方法获取Document对象Stringhtml="https://wall.alphacoders.com/featured.php?lang=Chinese";Documentdoc=Jsoup.connect(html).get();内容过长,就不再显示。我们以这部分为例:AboutUsFAQPrivacyP

不用数据库来实现用户的简单的下载,代码如下,但是却不能下载,请高手找下原因,文件路劲什么的没问题。<?phpfunction down_file($file_name,$file_sub_dir){//为防止乱码使用函数iconv$file_name=iconv("utf-8","gb2312",$file_


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software
