我有一个jsswitch 声明,用于检查提交的文本中是否存在特定字符串。
var textA= //regex
var textB= //regex
switch(true) {
  case textA.test(input):
    // CASE A
      $ajax ({
        type:"post",
        url:"process.php",
        data: {input:input,age:age,city:city,type:type},
        success: function(html){alert(html);} });
      break;
  case textB.test(input):
    // CASE B
      $ajax ({
        type:"post",
        url:"process.php",
        data: {input:input,width:width,height:height,type:type},
        success: function(html){alert(html);} });
      break;
 case ...
 }
通常,我会创建专用php文件来处理每个$ajax.
但我怎样才能$ajax在一个单一的处理多个 POST php。
我为每个 ajax 数据包含了一个唯一标识符type:,这将作为我的 PHP 接收到的 ajax 的参考
但我不确定如何正确编码 PHP 来处理提交的 $_POST 类型。
<?php
      //get post type from submitted AJAX
      $type = $_POST;
      switch($type) {
        case 0:
          $type= "caseA"
          //some code here
        case 1:
          $type= "caseB"
          // some code here
      }
 ?>