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.

    评论

报告相同问题?