douzhao7634 2011-09-04 05:02
浏览 44
已采纳

在不使用iframe的情况下在jQuery弹出窗口中打开PHP文件

I have a jQuery popup box made with a div. When the user clicks a button, this popup will open. This popup contains a form, populated dynamically based on a key sent via POST/GET with jQuery.

  1. How to I generate this form dynamically using these POST/GET variables?
  2. How do I include a form within this popup, without using an iframe?
  • 写回答

2条回答 默认 最新

  • doujiu7680 2011-09-04 05:22
    关注

    Well you can use the $.ajax() function of jQuery that upon a click event will send a request to a - sort of - a web-service script which will grab that variable and then respond with the HTML content of the dynamic form.

    Using the returned data along with $.html() function you can set the wrapper's innerHTML with the returned HTML and you will have your form.

    Small example:

    jQuery Code

    $("#button").click(function() {
        formID = 'form1';
    
        $.ajax({
            url: "formGenerator.php",
            type: "POST",
            data: formID,
            success: function(data) {
                if (data.length > 0)
                    $("#popupWrap").html(data);
            }
         });
    });
    

    PHP Code

    <?php
        // PHP Code 
        if (isset($_POST['data']) && !empty($_POST['data']))
        {
            switch($_POST['data'])
                case 'form1':
                    echo '<form name="FormName" action="" method="POST"><input type="text" /><input type="submit" value="Submit" /></form>';
                break;
                case 'form2':
                    echo '<form name="FormName2" action="" method="POST"><input type="text" /><input type="submit" value="Submit" /></form>';
                break;
        }
    ?>
    

    Notice: this code hasn't been tested, I wrote it from the top of my head, but it should get you going.

    http://api.jquery.com/jQuery.ajax/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 slam rangenet++配置
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊