AJAX - 如何在弹出菜单中运行脚本

时间:2014-10-20 16:03:09

标签: javascript php jquery html ajax

我有一个弹出菜单,可以打开并显示文本。我想要的是能够将控制器附加到弹出菜单。例如:我想要一个编辑配置文件弹出窗口,显示所有必要的输入以编辑配置文件。

userprofile_view.php:

        <div class="upload">
    <?php
        $data = array('id' => 'test'); 
        echo form_open('', $data); 
        echo form_submit('upload', 'Upload'); 
        echo form_close(); 
    ?>
    </div>      
<div id="popupbox">     
            <center>
                <p class="head">Terms and Conditions</p>

                <p class="term_full">By entering your email, you allow Musiclear to send you information regarding Musiclear and 
                    related services <br><br> By entering your email, you also understand that you can break our hearts and unsubscribe 
                    at anypoint.  <br><br> And feel free kick us if we ever share your email address (you can trust us)</p>
            </center>

        </div> 

这是按钮和弹出窗口后面的html。

main.js:

$( "#test" ).submit(function( event ) {
   event.preventDefault();
   document.getElementById('popupbox').style.visibility="visible";
});

点击按钮,我可以看到表格。

如何使用弹出菜单中的表单进行此操作?

修改

上传控制器(我想在弹出窗口中显示):

function do_upload_profilepicture()
{

$this->load->model('model_users');
$userID = $this->model_users->getUserID($this->session->userdata('username'));

$config['upload_path'] = './img/profilepictures/';
$config['allowed_types'] = 'jpg|png';
$config['overwrite'] = TRUE;
$config['file_name'] = $userID;
$config['max_size'] = '500';
$config['max_width']  = '1920';
$config['max_height']  = '1028';

$this->load->library('upload', $config);


if ( ! $this->upload->do_upload())
{
    $error = array('error' => $this->upload->display_errors());

    $this->load->view('upload_profilepic_form', $error);
}
else
{
    $upload_data = $this->upload->data();

    $resize['image_library'] = 'gd2';
    $resize['source_image'] = $upload_data['full_path'];
    $resize['maintain_ratio'] = FALSE;
    $resize['width']     = 180;
    $resize['height']   = 180;

    $this->load->library('image_lib', $resize); 
    $this->image_lib->resize();     
    $this->image_lib->clear();
    $this->model_users->setProfilePic($userID, $upload_data['orig_name']);


    $this->create_thumb($upload_data['orig_name']);
    redirect('userprofile/home/' . $userID);


}
}

userprofile_view.php(popupbox):

        <div id="popupbox">     
        <?php echo form_open_multipart('upload/do_upload_profilepicture');?>


        <input type="file" name="userfile" size="20" />

        <br /><br />

        <input type="submit" value="upload" />

        </form>

    </div> 

1 个答案:

答案 0 :(得分:1)

将您的函数调用放在脚本标记内 -

<div id="popupbox">

    <?php 
        echo '<script type="text/javascript">';
        echo "form_open_multipart('upload/do_upload_profilepicture');";
        echo '</script>';
    ?>
    <input type="file" name="userfile" size="20" />
    <br /><br />
    <input type="submit" value="upload" />
    </form>
</div>