dtv995719 2015-04-16 12:48
浏览 96
已采纳

在javascript中加载php页面

I have popup class in javascript and added all scripts in my html page that are required to display that popup. I am trying to load PHP page in that popup on submit button click of my form.

Popup is working fine for button like below (text from select.php is showing on popup box):

<a href="select.php" class="home-banner-button popup">Activate</a>

Now I have a form and on submit I have to redirect to PHP page depending on condition. And result should be display in popup.

I tried to load page with my popup class as below but its not showing the popup.

markup like below:

<form method="post" action="#"  onSubmit="return check();">
   <input type="text" id="textid" placeholder="Enter Here" />
   <input type="submit" name="submit" />                
</form>

Javasript:

<script type="text/javascript">

$(function () {
    $('.popup').colorbox({
        iframe: true,
        opacity: 0.7,
        fixed: true,
        innerWidth: 500,
        innerHeight: 180,
        scrolling: false
    });
});

function check() {
    var price = $('#textid').val();
    var new_value = price.replace(/\,/g, '');
    var lower_limit_value = 375;
    var upper_limit_value = 1712;

    if (new_value >= lower_limit_value && new_value <= upper_limit_value) {
        $(".popup").load("correct.php");
        return false;
    } else {
        $(".popup").load("incorrect.php");
        return false;
    }
}
</script>

I think I am using wrong syntax of this $(".popup").load("correct.php");

I am not getting how to use that/how do I call a class(e.g .popup) in javascript with loading php page or other way of doing this.

or How to use ajax in this case? Can ajax will help in such situation?

  • 写回答

3条回答 默认 最新

  • duanpaotian2348 2015-04-17 08:14
    关注

    I solved my problem by using .colorbox() function directly as below. Its working fine now. :)

    <script type="text/javascript">
        function check() {
            var price = $('#textid').val();
            var new_value = price.replace(/\,/g,'');
            var lower_limit_value = 375;
            var upper_limit_value = 1712;
    
        if (new_value>=lower_limit_value && new_value<=upper_limit_value) {
    
        $.colorbox({
    href:"correct.php",
    iframe:true, 
    opacity:0.7, 
    fixed:true, 
    innerWidth:500, 
    innerHeight:250, 
    scrolling:false});
        return false;
    
        } else {
    
        $.colorbox({
    href:"incorrect.php",
    iframe:true, 
    opacity:0.7, 
    fixed:true, 
    innerWidth:500, 
    innerHeight:320, 
    scrolling:false});  
        return false;
    
        }
    }
    
    </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?