动态获取文本框id jquery php

动态获取文本框id jquery php,php,jquery,textbox,Php,Jquery,Textbox,如何使用jquery ajax检索动态文本框id并将其传递给PHP JQUERY AJAX: $("#book_event").submit(function(e) { $(this).find('input[id^=textbox]').each(function(i, e) { $.post("Scripts/book_event.php", { att_name: $(e).val() }, function(data) { if (dat

如何使用jquery ajax检索动态文本框id并将其传递给PHP

JQUERY AJAX:

$("#book_event").submit(function(e) {
    $(this).find('input[id^=textbox]').each(function(i, e) {
        $.post("Scripts/book_event.php", {  att_name: $(e).val() }, function(data) {
            if (data.success) {
                $("#err").text(data.message).addClass("ok").fadeIn("slow");
            } else {
                $("#err").text(data.message).addClass("error").fadeIn("slow");
            }
        }, "json");
    });
    e.preventDefault();
});
如何使用PHP获取这些id:

if(!$_POST['submit']) :
   $att_name = trim($_POST['att_name']);
endif;

我会将所有文本框输入收集到一个javascript数组中,然后将其发送到php脚本。这样,您只需要一个ajax调用,而不是n

var input_array = {events:[]};
$("#book_event").submit(function(e)
{

    $(this).find('input[id^=textbox]').each(function(i, e)
    {
        input_array.events.push(e.val());
    });


    //send array via ajax
    $.ajax
    ({
      url:  "Scripts/book_event.php",
      type:"POST",
      data:JSON.stringify(input_array),
      contentType:  'application/json; charset=utf-8',
      dataType:"json",
      success:function(data){//func on success},
      error:function(data){//func on error}
    });

    e.preventDefault();
});
在服务器端,现在必须检索已发送的json对象:

$dto = json_decode($GLOBALS["HTTP_RAW_POST_DATA"]);

foreach($dto->events AS $event)
{
   //do your work here
}
//output response
我认为直接读取HTTP_RAW_POST_DATA应该存在安全问题,最好在解码为json之前检查它