简体   繁体   English

PHP在Bootstrap Modal中发出HTTP GET请求

[英]PHP Make HTTP GET Request in Bootstrap Modal

I have a Bootstrap Modal dialog that appears when you click on a link on the body of the page. 当您单击页面正文上的链接时,会出现一个Bootstrap Modal对话框。 It contains a button to make a call via a VOIP service - here's the modal code: 它包含一个通过VOIP服务进行呼叫的按钮-这是模式代码:

 <div class="modal" id="callModal"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button> <h4 class="modal-title">Call Customer</h4> </div> <div class="modal-body"> <p>Calling Fred Flinstone . . . </p> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button> <a href="<?php echo $contact1CallBack ;?>" id="callContact"><button type="button" class="btn btn-success">Make Call</button></a> </div> </div> <!-- /.modal-content --> </div> <!-- /.modal-dialog --> </div> <!-- /.modal --> 

When the user clicks the Make Call button at the moment it calls the URL in the same window - I would like to remain in the modal window and make the call the HTTP url in the background but not sure how to do this? 当用户在同一窗口中调用URL时单击“拨打电话”按钮时-我想保留在模式窗口中,并在后台调用HTTP URL,但不确定如何执行此操作?

From this: 由此:

<a href="<?php echo $contact1CallBack ;?>" id="callContact"><button type="button" class="btn btn-success">Make Call</button></a>

To change this: 要更改此设置:

<button type="button" id="makecall" class="btn btn-success">Make Call</button>

Jquery: jQuery的:

$("#makecall").click(function(){

 $.ajax({

           url:$yoururl/method,
           data:{},
           method:"POST",
           success:function(data){

            }

       });

    });

This will keep you rmodal as it is. 这将使您保持rmodal不变。 In success funciton inside ajax call, you can put code to do what you want to after call is made successfully. 在ajax调用内部的成功功能中,可以在调用成功后放入代码以执行所需的操作。

You can make call of api using Ajax 您可以使用Ajax调用api

<a href="javascript:" onclick="callapi(<?php echo $contact1CallBack ;?>);" id="callContact"><button type="button" class="btn btn-success">Make Call</button></a>

And call API by this code 并通过此代码调用API

<script>
function callapi (api) {

                $.ajax({
                    url: api,
                    type: 'GET',
                    dataType: 'json',
                    crossDomain: true,
                    success: function (data, textStatus, xhr) {
                        console.log(data);
                    },
                    error: function (xhr, textStatus, errorThrown) {
                        console.log(errorThrown);
                    }
                });

        }
    </script>

So it will not reload your page and call API in background 因此它不会重新加载您的页面并在后台调用API

Hope this help you 希望这对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM