dongliulu1122 2015-02-07 14:28
浏览 32
已采纳

使用ajax-php发送变量时出错

I try make a login using ajax, but when sending the variables to a php file arriv empty..

ajax:

  function enviar()
  {
    var ced=$("#cedula").val();
    var con=$("#contraseña").val();
    $.ajax({
      async:true,
      type: "POST",
      dataType: "html",
      contentType: "application/x-www-form-urlencoded",
      url:"sesion/index.php",
      data:{"cedula": ced,"contraseña": con},
      beforeSend:inicioEnvio,
      success:llegada,
      error:problemas
    }); 
      return false;
  }

php code:

 $operaciones=new operaciones();
    $operaciones->conexion();
    if($operaciones->verificar_login('usuario','USU_Cedula',
       'USU_Contraseña',$_POST['cedula'],
        $_POST['contraseña'], $result)== 1){codigo}
  • 写回答

2条回答 默认 最新

  • duanli9930 2015-02-07 14:32
    关注

    In PHP, try the following code... it should give you a dump off everything sent..

    <?php
      echo "Request:<br /> ", print_r($_REQUEST,true), "<br />";
      echo "Get:<br /> ", print_r($_GET,true), "<br />";
      echo "Post:<br /> ", print_r($_POST,true), "<br />";
    ?>
    

    Otherwise, the js looks fine at a glance. i would suggest the POST method of jquery though.

    $.post( "sesion/index.php", { "cedula": ced,"contraseña": con }).done(function( data ) {
        alert( "Data Loaded: " + data );
    });
    

    Using post saves having to deal with some of the finer settings and should work in general use. PHP seems to play nicely with it as well..

    The before event can be just a call in front of the post command and there is a error function as well that can be used.

    EDIT

    Sorry, miss read it i think. By the looks of it, your not getting a value from your js vars..

    Try doing an alert straight after you obtain their value and try switching them in the post... try sending test strings to your PHP.

    var ced=$("#cedula").val();
    var con=$("#contraseña").val();
    alert(ced);
    alert(con);
    
    /* Try this in your post */
    data:{"cedula": "test1","contraseña": "test2"},
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作