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()
      }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)