csdn产品小助手 2014-05-24 00:39 采纳率: 0%
浏览 21

使用$ .ajax进行发布不起作用

Well, the problem is not new, as I saw (really surf a lot), but still can not find solution for myself.

Description of problem:

  1. Have local Web server - XAMPP;
  2. Firefox 29.0.1
  3. And trying to send POST with $.ajax

    function checkUser(){
      $.ajax({
        type: 'POST',
        url: 'ajax/checkUser.php',
        data: 'uname='+$("#username").val()+'&pword='+$("#password").val(),
        success: function(){
          someNewFunc();
        },
      });
    };
    

This function I'm calling with:

$(document).ready(function(){
        $(".button.postfix.login").on("click", function(){
        if (($("#username").val() != "") && ($("#password").val() != "")) {
            hide(); <-- hide pop ups about empty field
            checkUser();    
        } else {$("#empty").show();} <-- pop ups 
        });
    });

And here code of page with elements:

<input id="username" type="text" placeholder="Username" />
<input id="password" type="password" placeholder="Password" />

<a class="button postfix login" href="#" 
onclick="event.preventDefault();">Sign in</a>

I guess that data are going out, but the page checkUser.php doesn't get anything. What am I doing wrong?

P.S. checkUser.php:

<?php
print_r($_POST);
?>

Result - Array ( )

P.P.S. By the way, if POST change to GET it's working, but need to be POST

  • 写回答

2条回答 默认 最新

  • weixin_33708432 2014-05-24 00:49
    关注

    Does your someNewFunc callback fire? Do you see the HTTP AJAX request in the developer console in Firefox?

    Try sending your post data as a dictionary to $.ajax:

    $.ajax({
      type: 'POST',
      data: {
        uname: $("#username").val(),
        pword: $("#password").val()
      }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏