duanping5306 2015-11-17 15:03
浏览 51
已采纳

用于Jquery字符串的PHP urlencode

I'm struggling to finish a final piece of my project - I have a textbox that is populated by a date time picker in the format YYYY/MM/DD HH:MM

I need to pass this value in to a URL string, which is then sent to a database table.

As I''m using a modal to gather the additional information I need I have a Jquery script to alter my HREF tab on the submit button:

$(document).on('click','#myModal<?php echo $v['id']; ?> .modal-footer a', function(e)
            {
                e.preventDefault();
                //function to update HREf attribute with values from modal screen
                var uri = <?php urlencode('2016/01/01/ 21:00')?>
                //$('#divert_until_<?php echo $v['id']; ?>').text();

                window.location.href=window.location.href= $(this).attr('href') + '&to=' + $('#divert_to_<?php echo $v['id']; ?> option:selected').text() + '&type= ' + $('#divert_type_<?php echo $v['id']; ?> option:selected').text() + '&until= ' + uri;

            });

Currently, I receive all the information (ID, TO, and TYPE) but nothing from UNTIL. Above I am trying to save the fixed string '2016/01/01 21:00' to the database.

Here is my code to catch the URL:

if(isset($_GET['action']) && $_GET['action']=='add_divert') {

if(!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    $_SESSION['notification'] = array('type'=>'bad','msg'=>$lang['ADMIN_INVALID_ID']);
    redirect(ROOT_URL.'stores.php?search='.$_REQUEST['search'].$pg.$st.$fl);
}

$db = db_connect();
if($db->update('stores',array('divert_enabled'=>1,'divert_type'=>($_GET['type']),'divert_until'=>($_GET['until']),'divert_to'=>($_GET['to'])),$_GET['id'])) {
    $_SESSION['notification'] = array('type'=>'good','msg'=>'Divert notice added to destination.');
} else {
    $_SESSION['notification'] = array('type'=>'bad','msg'=>'Could not add a divert notice to the destination.');
}
redirect(ROOT_URL.'stores.php?search='.$_REQUEST['search'].$pg.$st.$fl);
}

I've tried a few variations, but am just going round in circles.

Ultimately I need to retried the date time string from ('#divert_until_<?php echo $v['id']; ?>').text()

Thanks!

  • 写回答

2条回答 默认 最新

  • dpo69086 2015-11-17 16:41
    关注

    MY bad, was using .text instead of .val

    final code:

    $(document).on('click','#myModal<?php echo $v['id']; ?> .modal-footer a', function(e)
         {
         e.preventDefault();
        //function to update HREf attribute with values
    
        var until_str = $('#divert_until_' + <?php echo $v['id']; ?>).val();
        var uri = encodeURI(until_str);
    
        window.location.href=window.location.href= $(this).attr('href') + '&to=' + $('#divert_to_<?php echo $v['id']; ?> option:selected').text() + '&type= ' + $('#divert_type_<?php echo $v['id']; ?> option:selected').text() + '&until=' + uri;
    
       });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 准备学习小程序搭建,谁能手把手的教我啊?
  • ¥15 关于#嵌入式硬件#的问题:树莓派第一天重装配置python和opencv后第二天打开就成这样,瞎捣鼓搞出来文件夹还是没把原来的界面调回来
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥20 Arduino 循迹小车程序电路出错故障求解
  • ¥100 AT89C52单片机C语言调试之后再回答
  • ¥15 AT89C52单片机C语言串口助手发送数据包返回值
  • ¥15 C++数组中找第二小的数字程序纠错
  • ¥15 wannier复现图像时berry曲率极值点与高对称点严重偏移
  • ¥15 利用决策森林为什么会出现这样·的问题(关键词-情感分析)
  • ¥15 DispatcherServlet.noHandlerFound No mapping found for HTTP request with URI[/untitled30_war_e