weixin_33711641 2016-12-13 19:04 采纳率: 0%
浏览 24

在页面加载时提交ajax

So I am submitting my AJAX just before the page is loaded and calling it on the same page like this after ajax.

<input type="text" class="hidden" id="storeID" value="<?php echo $_GET['store']; ?>">
$(document).ready(function()
{
var store = $("#storeID").val();
$.ajax(
{
  url: '../user-style.php',
  method: 'POST',
  data: {"store":store}
});
});
<link rel="stylesheet" href="../user-style.php" media="screen" />

user-style.php

if(isset($_POST['store']))
{
$stmtgetstyle = $mysqli->prepare("SELECT * FROM store_style_configuration WHERE store_id=?");
$stmtgetstyle->bind_param("i", $_GET['store']);
$stmtgetstyle->execute();
$getstyle = $stmtgetstyle->get_result();
$style = $getstyle->fetch_assoc();
$stmtgetstyle->close();
}

But user-style.php isn't getting any data neither any thing is from database is coming.

  • 写回答

2条回答 默认 最新

  • weixin_33675507 2016-12-13 19:07
    关注

    You are posting your data in the ajax call, but are binding to the variable $_GET['store']. Just change that to $_POST['store'] and it should work. This should have also sent out a notice error stating there was an undefined index 'store' in $_GET on line .... This is why turning on error_reporting(E_ALL) is good when in development.

    Edit: actually, on second thought, it might not have thrown an error because when using a variable by reference creates a variable if it doesn't exist and doesn't throw an error. I assume this is the same for undefined array indexes.

    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能