Re: Facebox won't load when page loads - how do I do it?
Posted: Fri Aug 29, 2014 10:54 am
How are you posting your data thru Ajax?
Mine's working for the page of thumbnails, and each button posts.
But when I put this into the product page, so they can request a sample from there it fails every time. No matter where I put the scrip
It even fails if I put the Form and scripts into their own test.inc file. The only page that is 100% reliable is the sample page that has the darkened box.
It's stuns me that test.inc won't even work all the time. That has nothing else in it. It works in test.php, so NO other code from the template is running, but then the samples page works within the template.
I am using a JS file, and a PHP file, along with the INC file.
Here it is - can it be reduced to just use the external PHP file, and would that make it more reliable for other pages where they are other scripts running?
AJAX File
Mine's working for the page of thumbnails, and each button posts.
But when I put this into the product page, so they can request a sample from there it fails every time. No matter where I put the scrip
It even fails if I put the Form and scripts into their own test.inc file. The only page that is 100% reliable is the sample page that has the darkened box.
It's stuns me that test.inc won't even work all the time. That has nothing else in it. It works in test.php, so NO other code from the template is running, but then the samples page works within the template.
I am using a JS file, and a PHP file, along with the INC file.
Here it is - can it be reduced to just use the external PHP file, and would that make it more reliable for other pages where they are other scripts running?
Code: Select all
<script>
$(document).ready(function() {
$(".submitcart").click(function() {
var form = $(this).parent('form');
var email = form.children('input[name=email]').val();
var prodid = form.children('input[name=prodid]').val();
var prodname = form.children("input[name=prodname]").val();
// etc
// Returns successful data submission message when the entered information is stored in database.
var dataString = '&prodid=' + prodid + '&prodname=' + prodname;
if (email == '') {
alert("Please Fill All Fields");
} else {
//AJAX code to submit form.
$.ajax({
type: "POST",
url: "ajax_sendtofriend.php",
data: dataString,
cache: false,
success: function(result) {
}
});
}
return false;
});
});
</script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
function toggle_visibility(id) {
var e = document.getElementById(id);
e.style.display = ((e.style.display!='none') ? 'none' : 'block');
}
</script>
<div id="light" class="white_content">
<div class='white_content_head'>
<div class='head' style='margin-top: 0px; padding: 10px'>Sample Added</div>
</div>
<div id="light" class="white_content_inner">
This Sample has been added to your cart.<br/><br/><br/>
<table align='center'><tr><td style='padding-right: 15px'><a href='/cart/' class='btn_cart_popup_black'>Place Order</a></td><td>
<a href="javascript:void(0)" onclick ="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'" class='btn_cart_popup_blue'>Continue Shopping</a></td></tr></table>
</div></div>
<div id="fade" class="black_overlay"></div>
<div id='form1'>
<form>
<input type='hidden' id='email' name='email' value='445'>
<input type='hidden' id='prodid' name='prodid' value='445'>
<input type='hidden' id='prodname' name='prodname' value='Simon test'>
<input type='button' id='submit' value='REQUEST SAMPLE' class='submitcart' onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'"/>
</form>
</div>
Code: Select all
<?php
session_start();
$today = date('Y-m-d');
$cookieuserid = isset($_COOKIE['userid']) ? $_COOKIE['userid'] : null;
$sessionid = isset($_SESSION['sessionid']) ? $_SESSION['sessionid'] : null;
$email = isset($_POST['email']) ? $_POST['email'] : null;
$prodid = isset($_POST['prodid']) ? $_POST['prodid'] : null;
$prodname = isset($_POST['prodname']) ? $_POST['prodname'] : null;
include "dbconn.php";
if (isset($cookieuserid))
{
$resultcheck = mysql_query ("SELECT id FROM samples WHERE userid = '$cookieuserid' AND status = 'added'");
}
else
{
$resultcheck = mysql_query ("SELECT id FROM samples WHERE userid = '$sessionid' AND status = 'added'");
}
$num_disable = mysql_num_rows($resultcheck);
if ($num_disable == "6") { $disable = "yes";
}
else
{
$disable = NULL;
if (isset($cookieuserid))
{
$resultcheck = mysql_query ("SELECT id FROM samples WHERE prodid = '$prodid' AND userid = '$cookieuserid' AND status = 'added'");
}
else
{
$resultcheck = mysql_query ("SELECT id FROM samples WHERE prodid = '$prodid' AND userid = '$sessionid' AND status = 'added'");
}
$num_sample = mysql_num_rows($resultcheck);
if ($num_sample == 0)
{
if (isset($cookieuserid))
{
mysql_query("INSERT INTO samples (userid, prodid, prodname, dateadded, status) VALUES ('$cookieuserid', '$prodid', '$prodname', '$today', 'added')");
}
else
{
mysql_query("INSERT INTO samples (userid, prodid, prodname, dateadded, status) VALUES ('$sessionid', '$prodid', '$prodname', '$today', 'added')");
}
}
}
?>