简体   繁体   English

PHP脚本无法通过Ajax调用执行

[英]php script doesn't execute with ajax call

i need your help. 我需要你的帮助。

i have some input with a button like this. 我有一些像这样的按钮输入。

<input type="text" name="cmsperso" id="cmsperso" />
<input type="text" name="chefdequart" id="chefdequart" />
<input type="text" name="adjoint" id="adjoint" />
<button type="submit" name="perso" onClick="perso()">envoyer</button>

the onClick call an ajax function. onClick调用ajax函数。

function perso() {
$.ajax({
  type: "POST",
  url: "form/perso.php",
});}

and in my perso.php, i have this update. 在我的perso.php中,我有此更新。

$cnx = mysql_connect( "localhost", "root", "" );
$db = mysql_select_db( "maincourante" );
$req = mysql_query("SELECT idops FROM ops ORDER BY idops DESC LIMIT 1");
$data = mysql_fetch_array($req);

$cmsperso = $_POST["cmsperso"];
$chefdequart = $_POST["chefdequart"];
$adjoint = $_POST["adjoint"];

$perso = utf8_decode("UPDATE `Opérations n°".$data['idops']."` SET cmsperso='$cmsperso', chefdequart='$chefdequart', adjoint='$adjoint'");

mysql_query($perso, $cnx) or die(mysql_error());
mysql_close();

all is working fine exept the update. 一切正常,除了更新。 In phpmyadmin none of the value is update. 在phpmyadmin中,所有值都不是update。

please help 请帮忙

you are not sending the variable values in your post, 您没有在帖子中发送变量值,

function perso() {
$.ajax({
  type: "POST",
  url: "form/perso.php",
});}

need to add the variable and value to this call like: 需要将变量和值添加到此调用中,例如:

function perso() {
$.post("form/perso.php", { adjoint: $("#adjoint").val(), cmsperso: $("#cmsperso").val(), chefdequart: $("#chefdequart").val() } );
});}

also take a look at PDO for managing your data objects as your query can be injected into 还可以看看PDO用于管理数据对象,因为可以将查询注入

finaly it seems you have no where clause, this means that ALL lines in your table will be updated which probably not what you were after. 最后,似乎您没有where子句,这意味着表中的所有行都将被更新,而这可能不是您想要的。

another think i would consider is naming you table something simpler than it is now having spaces and special charaters in there is asking for trouble. 我想考虑的另一种想法是为您的表命名比现在具有空格和特殊字符的表更简单,这会带来麻烦。

Are you sure Opérations n°".$data['idops']." 您确定要操作Opérations n°".$data['idops']." is the correct table you are trying to update? 您要更新的正确表是什么?

good morning, 早上好,

i think, i partially resolve my problem 我认为,我可以部分解决我的问题

this is my code 这是我的代码

function getXMLHttpRequest() {
var xhr2 = null;

if (window.XMLHttpRequest || window.ActiveXObject) {
    if (window.ActiveXObject) {
      try {
        xhr2 = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e) {
        xhr2 = new ActiveXObject("Microsoft.XMLHTTP");
      }
    } 
    else {
      xhr2 = new XMLHttpRequest();
    }
  } 
  else {
    alert("Votre navigateur ne supporte pas l'objet XMLHTTPRequest...");
    return null;
  }
  return xhr2;
}

/* ressources */
function perso() {
  $.post("form/perso.php", { 
    cmsperso: $("#cmsperso").val(), 
    chefdequart: $("#chefdequart").val(),
    adjoint: $("#adjoint").val()
  });

  var xhr2 = getXMLHttpRequest();

  xhr2.open("POST", "form/perso.php", false);
}

and this return in firebug 并在萤火虫中返回

找到萤火虫302

any idea? 任何想法?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM