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 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败