Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Ajax向php传递数据_Php_Jquery_Ajax - Fatal编程技术网

使用Ajax向php传递数据

使用Ajax向php传递数据,php,jquery,ajax,Php,Jquery,Ajax,尝试使ajax调用正常工作 jQuery代码 <script> jQuery( document ).ready(function() { jQuery.ajax({ url: "/handler/?Action=Variable", data: { "Action": "Variable" }, cache: false, type: "GET", success: function(response) {

尝试使ajax调用正常工作

jQuery代码

<script>
jQuery( document ).ready(function() {
jQuery.ajax({
    url: "/handler/?Action=Variable",
    data: { 
        "Action": "Variable"
    },
    cache: false,
    type: "GET",
    success: function(response) {
        alert(response);
    },
    error: function(xhr) {
        alert(xhr);
    }
});
}
</script>

$.ajax({
var name='myname';//示例这是来自ajax的变量
类型:'POST',
url:“../page.php,//获取变量的页面
数据:'name='+名称;
成功:函数(数据){}
});
并从AJAX中获取传递的变量

<?php    
    if (isset($_POST['name'])){
        $name =$_POST['name'];

    }
?>


@Luke_-Spring了解ajax的最佳方式是以纯粹的方式进行,只有在这是使用JQuery等框架的好解决方案(对我来说还不是时间问题)之后。同时,对于你未来的职业生涯来说,最好能知道引擎盖下面发生了什么。你会犯什么错误?404? 或者其他?我想错误在你的url中,因为我尝试了你的代码,它工作正常。他已经理解了,所以不需要告诉他。常识,兄弟。
Array
(
    [Action] => Variable
    [_] => 1450086386289
)   
<script>         
    $.ajax({
        var name='myname'; //exampls this is your variable from ajax
        type:'POST',
        url: '../page.php, //the page where you get the  variable
        data:'name=' + name;
        success:function(data){}
        });
</script>
<?php    
    if (isset($_POST['name'])){
        $name =$_POST['name'];

    }
?>