使用ajax show打开新窗口 [英] using ajax show open new window

查看:44
本文介绍了使用ajax show打开新窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此代码中有一些与链接有关的错误,它没有打开页面.我提供的链接中可能有错误,并且没有显示警告,其中有其他链接的数据页面.在我的PC中,文件的链接为"D:\ xampp \ htdocs \ cart \ welcome.php",这意味着其在文件夹"D:\ xampp \ htdocs \ cart"中,现在我进行了更改以使其正确,我在我的电脑上使用xampp来使用它,不会使网站

in this code there is some error related to the link and it is not opening the page .there error may be in the link that i am giving and it is not showing the alert in which it will have the data of the other page .in my pc the link of the file is "D:\xampp\htdocs\cart\welcome.php" means its in folder "D:\xampp\htdocs\cart" now what i change to make it right and i am using this on my pc with xampp not making webstie

 <html>
<head>
<script>  
  function check(form) {
  if (form.email.value == "id@gmail.com") {
    document.getElementById("displayu").innerHTML ="correct username".fontcolor("green");
  } else if (form.email.value == "") {
    document.getElementById("displayu").innerHTML ="<font color='red'>blank username</font>";
  } else if (form.email.value != "") {
    var email = document.getElementById('email');
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if (!filter.test(email.value)) {
      document.getElementById("displayu").innerHTML ="Please provide a valid email address";

    }
       else {document.getElementById("displayu").innerHTML ="wrong email";} 
 } 

  if (form.pswrd.value == "123") {
    document.getElementById("displayp").innerHTML ="correct password";
  } else if (form.pswrd.value == "") {
    document.getElementById("displayp").innerHTML ="<span style='color:red'>blank password</span>";
  }
 else {document.getElementById("displayp").innerHTML ="wrong password";} 
  makeRequest('http://D:/xampp/htdocs/cart/welcome.php');
    }


  function makeRequest(url) {
    httpRequest = new XMLHttpRequest();

    if (!httpRequest) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
    }
    httpRequest.onreadystatechange = alertContents;
    httpRequest.open('GET', url);
    httpRequest.send();
  }

  function alertContents() {
    if (httpRequest.readyState === XMLHttpRequest.DONE) {
      if (httpRequest.status === 200) {
        alert(httpRequest.responseText);
		document.open();
        document.write(httpRequest.responseText);
        document.close();
        
      } else {
        alert('There was a problem with the request.');
      }
    }
  }
</script>  
</head>
<body>
<h1>for login</h1>
<h3>email=id@gmail.com   and password=123</h3>
<form name="login">
<div id="displayu"></div>
<div id="displayp"></div>
  Username <input type="text" name="email" id="email" />
  Password <input type="password" name="pswrd"/>
  <input type="button" onclick="check(this.form)" value="Login" />

  <input type="reset" value="reset"/>
</form>

</body>
</html>

推荐答案

您需要运行Web服务器,然后使用网络名称(例如 http://localhost/cart/welcome.php)从中请求资源.).

You need to run a webserver and then request your resource from that using a network name (e.g. http://localhost/cart/welcome.php).

指向本地文件路径的URL将以 file:而不是 http:开头,但是XMLHttpRequest的大多数实现都会拒绝支持它,并且不会导致要执行的PHP(因为在这种情况下,PHP是一种服务器端编程语言).

A URL to a local filepath would start with file: instead of http:, but most implementations of XMLHttpRequest would refuse to support it, and it wouldn't cause the PHP to be executed (since PHP, in this context, is a server side programming language).

这篇关于使用ajax show打开新窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆