English 中文(简体)
PHP: Ajax-to-PHP 参数问题
原标题:PHP: Ajax-to-PHP parameter issue
  • 时间:2012-01-12 14:55:21
  •  标签:
  • php

用下文指定的Ajax代码,在我的网页标题ETD2.html上,该代码将一个参数发送至载有开关说明的php文字。 问题一是,为使开关说明能够正确运作,参数必须不止包括几个,而对于我方的争 que,我需要一个等于参数的变量,尽管它只包含变数和别的东西。

Ajax:

<script type="text/javascript">
function doAjax(ajaxFunction, str)
{ 
if (str=="")
  { document.getElementById("txtHint").innerHTML="";
  return; }
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)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText; }
  }
xmlhttp.open("GET","getuser.php?q="+str+"func="+ajaxFunction,true);
xmlhttp.send(); }
</script>

PHP:

<?php

include("dbinfo.inc.php");
$con = mysql_connect(localhost, $username, $password);
if (!$con)
    {
    die( Could not connect:   . mysql_error());
    }

$db_selected = mysql_select_db($database, $con);
if (!$db_selected)
    {
    die( Could not connect to   . $database .  <br />  . mysql_errno() .  :   . mysql_error());
    }

$sFunction  = $_GET["func"];
$q=$_GET["q"];

switch($sFunction){
    case  showCharacters :
       $result = mysql_query("SELECT * FROM `tablename` WHERE id =  " . mysql_real_escape_string($q) . " ") or die(mysql_error());
    Display Info from Database.
    break;
    case  showTowers :
       $result = mysql_query("SELECT * FROM `tablename` WHERE id =  " . mysql_real_escape_string($q) . " ") or die(mysql_error());
    Display Info from Database.
    break;
    case  showEnemies :
       $result = mysql_query("SELECT * FROM `tablename` WHERE id =  " . mysql_real_escape_string($q) . " ") or die(mysql_error());
    Display Info from Database.
    break;
    }
?>

我曾尝试过几个不同的事情,但没有任何工作。 我所尝试的一件事是,由于参数是在文字开始时变成一个变数,我把它变成了一种扼杀,并尝试了“替代”的表述,但这种影响仍未产生。 我是否可以认为我没有使用正确的yn子? 我不相信。 我不十分了解购买力平价,但我相信我是正确的。

参数以这种格式传送到文字上:(“数量” func=“父母姓名”=2func=showTowers

这是我所尝试的,尽管它没有工作。

$para =$_GET["q"];
$bres = (string)$para;
$ares = preg_replace("/[^0-9]/","", $bres); 

感谢任何帮助。 请不要对 j笑发表评论,也不对我的问题如何.。 如果确实如此,我将不要求帮助。

最佳回答

你没有像你应该的那样,把你的问答变量与安放器区分开来。 这是:

xmlhttp.open("GET","getuser.php?q="+str+"&func="+ajaxFunction,true); 
                                         ^
                                         |
ADDED! ----------------------------------/
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签