1

送信されたテキストに特定の文字列が存在するかどうかを確認する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通常、それぞれの POST データを処理する専用のファイルを作成します$ajax

$ajaxしかし、単一の で複数の POST を処理するにはどうすればよいですかphp

type:各 ajax データに一意の識別子を含めました。これは、PHP が受信している ajax に関する参照になります。

しかし、送信された $_POST タイプを処理するために PHP を適切にコーディングする方法がわかりません。

<?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
      }
 ?>
4

2 に答える 2