如何使用ajax和javascript响应div中的打印以及下面代码中的错误是什么 [英] how to response print in div using ajax and javascript and what is error in below code

查看:82
本文介绍了如何使用ajax和javascript响应div中的打印以及下面代码中的错误是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

index.php

----------------

index.php
----------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2" />
<title>Example Ajax GET</title>

<script type="text/javascript"><!--

 function showUser()
{
    var str = document.getElementById('pid').value;
    //alert(str);
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
     //alert("testttt");
     document.getElementById("test").innerHTML = xmlhttp.responseText;
     //alert(str);
    }
  }
xmlhttp.open("GET","test1.php?q="+str,true);
xmlhttp.send();

}

</script>
</head>
<body>

<form action="#" method="post">
Enter Text:<input type="text" id="pid"/>
<input type="submit"  value="save" onclick="showUser();"/>
</form>
<div id="test"></div>
</body>
</html>





test1.php

-------------------



test1.php
-------------------

<?php
$con =mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("ebaynew",$con) or die(mysql_error());
$id = $_GET['q'];
$query ="select * from productdetails where ebayId = $id";
$res = mysql_query($query) or die(mysql_error());
$no = mysql_num_rows($res);
if($no > 0)
{
    //$msg = "Product Already Exist";
    echo "Product Already Exist";
}
?>

推荐答案

con = mysql_connect( localhost root die(mysql_error());
mysql_select_db( ebaynew
con =mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("ebaynew",


con ) die(mysql_error());
con) or die(mysql_error());


id =
id =


这篇关于如何使用ajax和javascript响应div中的打印以及下面代码中的错误是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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