jQuery的阿贾克斯方法="邮电QUOT;但$ _ POST空 [英] Jquery .ajax method="post" but $_POST empty

查看:143
本文介绍了jQuery的阿贾克斯方法="邮电QUOT;但$ _ POST空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$.ajax({
    method: "post"
    , url: "save.php"
    , data: "id=453&action=test" 
    , beforeSend: function(){

    } 
    , complete: function(){ 
    }  
    , success: function(html){ 
        $("#mydiv").append(html);        
    }
});

我已经设置方法类型后,但在Save.php我只是得到要么但不是在$ _GET或$ _REQUEST $ _ POST值。

I have set method type as post but in Save.php I just get values either in $_GET or $_REQUEST but not in $_POST.

我的表看起来像

<form method="post" id="myform" action="save.php">

这是行不通的,看了看周围,并在这里对谷歌,试图加入加密类型

It was not working, looked around here and on Google, tried adding enctype

<form method="post" id="myform" action="save.php" enctype="application/x-www-form-urlencoded">

但还是$ _ POST空?

but still $_POST empty?

我如何使它工作?谢谢你。

How do I make it working? Thanks.

推荐答案

而不是方法:文章则需要使用键入: POST

所以这应该没有任何改动你的HTML表单:

So this should work without any alterations to your form HTML:

$.ajax({
    type: "POST"
    , url: "save.php"
    , data: "id=453&action=test" 
    , beforeSend: function(){

    } 
    , complete: function(){ 
    }  
    , success: function(html){ 
        $("#mydiv").append(html);        
    }
});

不知道为什么它不工作,但这个工作对我来说:

Not sure why it doesn't work but this works for me:

save.php

<?php
print_r($_POST);

file.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>Example</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript">
    	$(function() {
    		$('input').click(function() {
    			$.ajax({
    				type: "POST"
    				, url: "save.php"
    				, data: "id=453&action=test" 
    				, beforeSend: function(){

    				} 
    				, complete: function(){ 
    				}  
    				, success: function(html){ 
    					alert(html);        
    				}
    			});
    		});
    	});
    </script>
</head>

<body>
    <div id="main"><input type="button" value="Click me"></div>
</body>
</html>

您错误必须位于其他地方。

Your error must lie somewhere else.

这篇关于jQuery的阿贾克斯方法=&QUOT;邮电QUOT;但$ _ POST空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆