doubu1853 2019-01-26 19:49
浏览 135
已采纳

无法在提交时从HTML表单获取jQuery中的值

I'm still working on things and I've almost got it done. The only issue I've got is in my jQuery code it don't send values to a php page. Ex: it should put "?whatever=whatever&soon=soon", but it don't. It leaves it blank.

I've tried changing code such as changing JS ids, and changing the code completely.

$(document).ready(function() {
var $userName = $("username");
var $text = $("text");
var $title = $("title");
var $chatSend = $("#chatSend");

function secret() {
    var userNameString = $userName.val();
    var textString = $text.val();
    var titleString = $title.val();

    $.get("./upload.php", {
        username: userNameString,
        text: textString,
        title: titleString
    });

    window.location.replace("success.php");

    }
}  

I expected it to put in my values (to my MySQL table), but instead they're all blank.

Here's my form. (When clicked on chatSend, it does the jQuery functions.)

<div>
<input type="text" id="text" name="text">
                <input type="text" id="title" name="title">
                <input type="text" id="username" name="username" hidden value="<?php echo htmlspecialchars($_SESSION['username']); ?>">
                <button id="chatSend">Send</button>
</div>

Also, here's the upload form now that I think about it (upload.php):

$user = $_GET['username'];

$title = $_GET['title'];

$text = $_GET['text'];

$query = mysqli_query($con, "INSERT INTO `blog` (username, title, text, view) VALUES ('$user', '$title', '$text', UUID())");

展开全部

  • 写回答

1条回答 默认 最新

  • dslkchyv673627 2019-01-26 20:03
    关注

    You need to use the proper identifier like you have with chatsend:

    //# = ID
    var $userName = $("#username");
    var $text = $("#text");
    var $title = $("#title");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部