0

我有 2 页,一个从表单发送数据并将数据发送到第二页。

第一个页面是html,第二个是php。

所以,我的问题是我将数据从表单发送到第二页以输入 SQL 语句,我从 fetch 数组中获取数据,我如何将数据从第二页发送到第一页并将其放入 div。

我将发送的 JS

// This function to search aqar
function search_aqar(){

    var city = $('#city').val();
    var aqar_type = $('#aqar_type').val();
    var adv_type = $('#adv_type').val();
    var search_btn = $('#search_btn').val();
    var show_type = $('#show_type').val();

    if (city!='' && aqar_type !='' && adv_type !=''){

    $.ajax({
      url: "request.php?do=search_aqar",
      type: "POST",
      data: {
             city        : city,
             aqar_type  : aqar_type,
             adv_type    : adv_type,
             show_type    : show_type,
             search_btn   : search_btn
          },
      dataType: "json",
      success: function(data){
      if(data.process == "ok"){

      }
      else
      {

      }
      }  
      });
    }
    else
    {

    }
}

我将数据获取到页面名称request.php并将变量放入 sql 语句,我需要将数据发送到 div 的第一页

4

2 回答 2

0

you may need to return the data as an json_encoded array from your php script and then use

success: function(data){
 var variable = jQuery.parseJSON(data);
 $("#yourdiv").html(variable['your_array_identifier']);
}

if you are not sending back an array and just a single item then you don't need to return an array and just simply use

   success: function(data){
     $("#yourdiv").html(data);
    }
于 2013-10-30T14:26:40.187 回答
0

Just put a div in your html file like this:

<div id="msg"></div>

And change this:

success: function(data){
  if(data.process == "ok"){

  }

To this:

success: function(data){
  $('#msg').html(data);  
}
于 2013-10-30T14:26:49.230 回答