duanhuan3012 2016-08-10 11:10
浏览 35
已采纳

当用户点击激活链接时,我如何向我的API发送确认回复

I am trying to send a confirmation message to my API after click on activation link , I am trying lot but failed , http://polestarllp.com/users/useractive.php?contranumberid=23215

    <script type="text/javascript">
         $(document).ready(function () {
             var person = "<?php $data; ?> ";
                 $.ajax({
                     url: 'http://192.168.1.102:1512/qlikapi/RegisterUser',
                     //type: 'Post',
                     data:person,
                     success: function (data, xhr) {
                     alert(data.ErrorMessage);
                     if(data.Success)
                     {
                    document.location.reload();  
                     }

                     },
                     error: function (xhr, textStatus, errorThrown) {
                         console.log('Error in Operation');
                     }
                 });



         });
    </script>
<style>
  • 写回答

2条回答 默认 最新

  • dtz8044 2016-08-10 13:17
    关注

    So far from what you said I have understood that you're trying to send a POST request whenever a user accesses your URL. Is that correct?

    In that case try something like this:

    <script type="text/javascript">
    
        $(window).ready(function(){
            $.ajax({
                type: 'post',  
                url: 'http://192.168.1.102:1512/qlikapi/RegisterUser',
                data: {'id' : 23215},
                success:(function(data){
                    alert('Success ' + data);
                }),
                error:(function(data){
                    console.error('Error ' + data);
                    alert('Error has occurred');
                })      
            });
        });
    
    </script>
    

    This will send a POST request to http://192.168.1.102:1512/qlikapi/RegisterUser straight after when the page loads, with id parameter and its value being 23215

    If you want to get the contranumberid from the URL, you can embed the PHP into your JS script like so:

    <script type="text/javascript">
    
        var contranumberid = <?php echo intval($_GET['contranumberid']);?>;
        $(window).ready(function(){
            $.ajax({
                type: 'post',  
                url: 'http://192.168.1.102:1512/qlikapi/RegisterUser',
                data: {'id' : contranumberid },
                success:(function(data){
                    alert('Success ' + data);
                }),
                error:(function(data){
                    console.error('Error ' + data);
                    alert('Error has occurred');
                })      
            });
        });
    
    </script>
    

    Note that I've added a new line: var contranumberid = <?php echo intval($_GET['contranumberid']);?>;

    This will assign a JS variable to the value of the GET contranumberid parameter and the POST that value to http://192.168.1.102:1512/qlikapi/RegisterUser.

    Hope this helps :)

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

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应