新手ajax和php获取参数

0 javascript php ajax jquery

我需要帮助做一些小事,但我不知道如何解决它.我有一个带有ajax的javascript文件,就像这样

$.ajax({
    data: "mc_id="+someid,
    url: "includes/getDataPrs.php",
    type: "GET",
    dataType: "json",
    async: false,
    success: function(msg){
          //some function here
    }
});
Run Code Online (Sandbox Code Playgroud)

在getDataPrs.php中

<?php
include_once 'db_connect.php';
include_once 'functions.php';

  sec_session_start();
  header('Content-Type: application/json');

  $id = null;
  $date = null;
  $limit = 0;
  if (isset($_GET['mc_id'])) {
    $id = $_GET['mc_id'];
  }
  //some process here $data
  echo json_encode($data);
Run Code Online (Sandbox Code Playgroud)

我可以从中获取数据,$_GET['mc_id']但是当我需要更多数据时,我会像这样在javascript中更改参数

$.ajax({
    data: "{'mc_id':'"+someid+"','limit':'"+somelimit+"'}",
    url: "includes/getDataPrs.php",
Run Code Online (Sandbox Code Playgroud)

然后我没有得到任何PHP $_GET['mc_id']$_GET['limit'] 我不顾一切地解决它,我把它放入网址"includes/getDataPrs.php?mc_id=someid&limit=somelimit

任何评论或建议我真的很感激提前感谢

urf*_*ion 5

传递多个变量ajax应该是这样的

$.ajax({
    data: {mc_id: someid, limit: some_limit},
    url: "includes/getDataPrs.php",
    type: "GET",
    dataType: "json",
    async: false,
    success: function(msg){
      //some function here
    }
});
Run Code Online (Sandbox Code Playgroud)

它总是更好用,data: {mc_id: someid, limit: some_limit}因为它会像对象本身一样对待.