【问题标题】:assign a name for ajax POST request为 ajax POST 请求分配一个名称
【发布时间】:2014-03-16 13:39:46
【问题描述】:

这是一个愚蠢的问题。 我有这个关联数组,我需要通过 ajax 请求发布:

var ajax_data = "{email: "email", pass: "password"}";

现在在我的 php 代码中,我应该通过 $_POST[something] 获取这些数据,对吗? 我的问题是 POST 请求的名称是什么? 我怎样才能改变它??? 坦克

【问题讨论】:

    标签: ajax post request


    【解决方案1】:

    我建议你看jquery doc for ajax

    这里是一个ajax方法的示例用法:

    $.ajax({
      type: "POST", // type POST or GET
      url: "some.php", // php file that data send to
      data: { name: "John", location: "Boston" } // here is your data in json format
    })
      .done(function( msg ) {
        alert( "Data Saved: " + msg );
      });
    

    数据格式很简单,就是这样的格式

    { key: 'value', anotherKey: 'anotherValue', ... }
    

    你可以像这样访问php中的数据

    $firstData = $_POST['key'];          // this variable contains 'value'
    $secondData = $_POST['anotherKey'];  // this variable contains 'anotherValue' 
    

    你写的任何东西,而不是 keyanotherKey 都是你在 $_POSTvalueanotherValue 中的变量的关键值

    【讨论】:

    • tanx aloooot,我在这里发疯了。这可能是我问过的最愚蠢的问题。希望我的朋友都没有看到。 ;)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 2015-07-23
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多