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

报告相同问题?

悬赏问题

  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题
  • ¥15 有没有人能解决下这个问题吗,本人不会编程
  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测