dongzaliang4492 2018-07-18 18:47
浏览 76

Ajax:php部分需要一个函数中的引号,而不是另一个函数中的引号

I have two different functions which both do Ajax calls.

In the first one I am assigning a string to the variable data: the part where I insert php Session variables is not in quotes

function insertMemberActivities()
{
    var data = "memId=" + <?php echo $_SESSION['memberId'];?> + "&acts=" + <?php echo $_GET['actID'] ;?> + "&comments=" + document.getElementById('comments').value;

    $.ajax({
        dataType: 'json',
        url: 'json-responses.php?fct=insertMemberActivities',
        data: data,
        cache: false,
        success: sendMailToMember(),
        // error: myCallbackError
    });
};

In the second one which looks similar however I have to add quotes around the php parts or otherwise it is not working

function sendMailToMember()
{
    var data = "eventName=" + "<?php echo $_GET['eventName'];?>" +
               "&userEmail=" + "<?php echo $_SESSION['user'] ;?>" + 
               "&first=" + "<?php echo $_SESSION['first']; ?>" + 
               "&last=" + "<?php echo $_SESSION['last']; ?>";

    $.ajax({
        dataType: 'json',
        url: 'stcg-json-responses.php?fct=emailSendToVolunteer',
        data: data,
        cache: false
    });
}

Does anyone have any idea why that could be?

  • 写回答

1条回答 默认 最新

  • dsk49208 2018-07-18 20:44
    关注

    some of the variables consist of only characters and numbers. those do not need quotes

    others have special characters like @ or . or spaces. in that case the expression has to be between quotes.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用