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

报告相同问题?

悬赏问题

  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮