送信されたテキストに特定の文字列が存在するかどうかを確認するjs
switch 宣言があります。
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
}
?>