对父页从FancyBox2更新选择框 [英] Update a Select Box on Parent Page from FancyBox2

查看:97
本文介绍了对父页从FancyBox2更新选择框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在的fancybox提交一个表单,用户可以添加一个公司一个选择框存在的情态动词父页上。林提交的模态信息,增加了公司给我的数据库的脚本这样做。然后我运行一个查询来获取所有更新的公司作为一个群体的标签。然后,我想这组标签传递给父页面作为jQuery更新。林不知道这是否是最好的办法还是我要去哪里错了。

I'm trying to submit a form in a fancybox where users can add a company to a select box that exists on the modals parent page. Im doing this by submitting the modal information to a script that adds the company to my database. Then I run a query to to get all the updated companies as a group of tags. Then I am trying to pass that group of tags to the parent page as a jquery update. Im not sure if this is the best approach or where I'm going wrong.

我试图用这个职位作为指南:

I am attempting to use this post as a guide:

查找元素上的网站从一个的fancybox IFRAME

不过,我有两个问题,我的code。 一:的fancybox不打烊 二:父页面上的选择框没有更新

But I have two problems with my code. One: The fancybox is not closing Two: The select box on the parent page is not updating

我不知道我要去的地方错了我的成功电话。从模态页面的code是:

I am not sure where I am going wrong with my success call. The code from the Modal page is:

$("#send-message").click(function(){
        $(this).closest('form').submit(function(){
            return false;
        });
        var frm = $(this).closest('form');        
         if($(frm).valid()){
            $("#ajax-loading").show();
            var data = $(frm).serialize();
            $(frm).find('textarea,select,input').attr('disabled', 'disabled');            
            $.post( 
                    "../forms/company_add.php", 
                    data,                   
                    function(data) {
                      if (data.success) {
                      // data.redirect contains the string URL to redirect to
                      $('#companyselect', $(parent.document)).html(data.success);
                      parent.$.fancybox.close();
                      }
                      else {
                        $("#ajax-loading").hide();
                        $(frm).find('textarea,select,input').removeAttr('disabled');
                        $("#send_message_frm").append(data.error);
                      }
                    },
                    "json"                  

           );
        }
    });

从company_add.php的code返回所有的选项标签,如这样的:

The Code from company_add.php returns all the options tags like such:

if ($_POST) {
        // Collect POST data from form
        $name     = filter($_POST['name']);
        $conmail  = filter($_POST['conmail']);
        $addy     = filter($_POST['addy']);
        $confax   = filter($_POST['confax']);
        $city     = filter($_POST['city']);
        $state    = filter($_POST['state']);
        $con      = filter($_POST['con']);
        $conphone = filter($_POST['phone']);
        $zip      = filter($_POST['zip']);
    }
    $search1   = mysql_query("SELECT man_name FROM manufacturers WHERE man_name = '$name'");
    $outcome1  = mysql_fetch_row($search1);
    $num_rows1 = mysql_num_rows($search1);
    $imageid1  = $outcome1[0];
    $imageid1  = filter($imageid1);
    if ($num_rows1 > 0) {
        echo json_encode(array(
            "error" => '<div class="msg-error">A company by that name already exists.</div>'
        ));
    } else {
        $stmnt = mysql_query("INSERT INTO manufacturers (manufacturer_id, man_name, man_address, man_city, man_state,man_zip, man_contact, man_phone, man_fax, man_mail) VALUES ('NULL', '" . $name . "', '" . $addy . "' ,'" . $city . "', '" . $state . "' , '" . $zip . "' , '" . $con . "' , '" . $conphone . "' , '" . $confax . "', '" . $conmail . "'  )");
        //echo "Duplicate WAS found:" . $answer1; 
        mysql_query($answer1);
        //}
        $resp['status'] = 'success';
        if (empty($error)) {
            $nada     = "SELECT man_name FROM manufacturers ORDER BY man_name ASC";
            $resulter = mysql_query($nada);
            $comp1    = '0';
            //Spit out array of companys as select boxes
            $select   = '<option value="">--Select one--</option>';
            while ($result59 = mysql_fetch_array($resulter))
                $select .= '<option value="' . $result59['man_name'] . '">' . $result59['man_name'] . '</option>';
            echo json_encode(array(
                "success" =>$select
            ));
        } else {
            echo json_encode(array(
                "error" => '<div class="msg-error">Error: Unable to add your company at this time</div>'
            ));
        }
    }

我是新来编程很新jQuery的,所以我希望有人可以看到我要去哪里错了。我使用的fancybox 2和PHP。

I am new to programming and very new to Jquery so I'm hoping someone can see where I'm going wrong. I am using fancybox 2 and php.

推荐答案

你检查错误控制台任何JavaScript错误?

Have you checked error console for any JavaScript errors?

您可以试试这个反正:

父$('#COMPANY选择)HTML(data.success);

这篇关于对父页从FancyBox2更新选择框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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