发送使用AJAX请求后两排 [英] Sending two arrays using ajax post request

查看:143
本文介绍了发送使用AJAX请求后两排的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AJAX / jQuery和PHP上的过滤器功能的工作/ mysql.I有两套复选框 1)=>为地区2)=>为地方 .The过滤器是类似以一个这里。我想送的两个复选框中的值来过滤records.The过滤器的地方将在当地过滤上的区域复选框中的选项。我已经得到它的工作高达一定程度 这就是所谓的在第一组的复选框。

I am working on a filter functionality using ajax/jquery and php/mysql.I have two sets of check boxes 1)=>for Regions 2)=>for Localities.The filter is similar to the one here. I want to send the values of both the check boxes to filter the records.The filter for localities will be locally filtered on the selection of a region check box.I have got it to work upto some extent This is called on the first set of check boxes.

HTML

<div class="locality">
                <input type="checkbox" id="checkbox1" class="checkbox1" value="<?php echo $suburb['suburb_name']?>" name="Suburb_check[]" onClick="changeResults();" onChange="" ><?php echo $suburb['suburb_name']?>  <span class="grey">(<?php echo $suburb['total']?>)</span>
            </div>
            <?php }?>

使用Javascript / jQuery的

function changeResults(){
    var data = { 'venue[]' : []};
        $("input:checked").each(function() {
            var chck1 = $(this).val();
            //alert(chck1);

                data['venue[]'].push($(this).val());

        });

    $.ajax({
     type : 'POST',
     url : 'process.php',
     data : data,
     success : function(data){


          $('#project_section').html(data); // replace the contents coming from php file

            }  
        });

   $.ajax({
     type : 'POST',
     url : 'loadLocality.php',
     data : data,

     success : function(data){
     document.getElementById("searchLoader").style.display = 'block';
              $('#localityList').html(data); // replace the contents coming from php file
        //   alert(data);
     document.getElementById("searchLoader").style.display = 'none'; 
            }  
        });  

    }

这是第二套CHCK盒与地方

This is the second set of chck boxes with Localities

<div class="locality" id="localities">
            <input type="checkbox" onClick="changeLocality();" id="1" value="<?php echo $locality['locality_name'];?>" name="Locality_check[]"><?php echo $locality['locality_name'];?> <span class="grey">(<?php echo $locality['total'];?>)</span>
        </div>

我已称为函数类似于上述之一,它贴到不同的网页。 这是第二个CHCK箱功能:

I have called a function similar to the above one and posted it to a different page. Here is the second chck box function:

function changeLocality(){
    var dataLocality = {'locality[]' : []};
        $("input:checked").each(function() {
            var chcklocal = $(this).val();
            //alert(chcklocal);
            dataLocality['locality[]'].push($(this).val());
        });

 $.ajax({
 type : 'POST',
 url : 'processLocality.php',
 data : dataLocality,
 success : function(dataLocality){
    // document.getElementById("newloader").style.display ="block";
          $('#project_section').html(dataLocality);        // replace the contents coming from php file
          //alert('data');
   // document.getElementById("newloader").style.display ="none";

        }  
    });

}

但是,当我选择的区域框,然后一个地方框,然后取消选择区域,我还获得了previous 本地值区数组中(数组的名称是场内)我只想地区去会场阵列和区域+地方当地数组中。其实,如果我取消该地区后续地方值也应该从array.Also除去,eventhough我张贴他们不同的页面区域页容纳的局部性values​​.I是卡作为没有太大的JQUERY知识。
通过帖子去了,但没能解决it.Any帮助将是AP preciated。

But,when I select a region box and then a locality box and then deselect the region,I also get the previous locality value in the region array(name of the array is venue)I want only regions to go in the venue array and regions+localities in the locality array.Actually,if I deselect the region subsequent locality value should also be removed from the array.Also,eventhough I am posting them to different pages the region page holds the locality values.I am stuck as not much of JQUERY knowledge.
Went through posts,but was not able to fix it.Any help would be appreciated.

修改 我得到一个数组,当我使用上述功能检查第一组CHCK箱,并且还筛选记录。

EDIT I get an array when I check the first set of chck boxes,and also filter the records using above functions.

Array
 (
    [venue] => Array
    (
        [0] => Pune East
        [1] => Pune West
        [2] => Pune North
        [3] => Pune South
    )

如果我现在点击任何第二套CHCK箱,我得到这样的数组。

If I now click on any of the second set of chck boxes,I get an array of this sort.

 Array
 (
  [locality] => Array
    (
        [0] => Pune East
        [1] => Pune West        //[0] and [1] are regions
        [2] => Aundh
        [3] => Kalyaninagar     //[2] and [3] are localities
    )

注意:一个区域可以有多个localities.But我想他们两个人是不同的数组,因为它们是两个不同的参数来SQL查询来过滤数据。 希望我再清楚不过了!
是我的做法吧??还是可以以更简单的方式来完成?
谢谢

Note: A region can have multiple localities.But I want both of them to be different arrays as they are two different parameters to the SQL query for filtering the data. Hope I am clear enough now!
Is my approach RiGHT??Or can it be done in an easier way?
Thanks

推荐答案

现在好了,我认为它是一个愚蠢的错误! :P 问题是与复选框的名字。在Javascript中,我们不能会场[] 括号[]在checkboxes.I $ P $的名称psumed它类似于PHP张贴阵列。 一些阅读后教训,并寻找!!!问题已解决 感谢那些谁回答。

Well now I think its a stupid mistake!! :P The issue was with the names of the checkboxes. In Javascript we cannot have venue[] brackets[] in the name of the checkboxes.I presumed it to be similar to PHP for posting arrays. Learnt it after some reading and search!!!Issue is resolved Thanks to those who answered.

这篇关于发送使用AJAX请求后两排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆