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

标签 javascript php jquery html ajax

我现在有一个弹出菜单,可以打开并显示文本。我想要的是能够将 Controller 附加到弹出菜单。例如:我希望显示一个编辑配置文件弹出窗口,其中包含编辑配置文件所需的所有输入。

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";
});

在按钮上单击“我使表单可见”。

如何在弹出菜单中使用表单来实现此功能?

编辑:

上传 Controller (我想在弹出窗口中显示的内容):

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(弹出框):

        <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> 

最佳答案

将函数调用放在脚本标签内 -

<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> 

关于javascript - AJAX - 如何在弹出菜单中运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26469996/

相关文章:

javascript - 在哪里以及如何修改嵌入的内容?

javascript - 在整个网站中查找字符串的一部分并替换为新文本

javascript - 垫自动完成功能未正确过滤 Angular

php - 将数组插入mysql表

javascript - 在 for 循环中分配点击处理程序

javascript - @observable 在 MobX 中是如何工作的?

php - MySql:需要提高查询性能

php - 使用 php 中的简单插入查询插入数据

jquery - Fancybox 2 从代码中打开 Iframe 版本

javascript - 带有基本 Jquery 的 django 没有响应