I'm making a card generator for fun and learning how to collect data from inputs and write to database.
When trying to send this simple piece of JSON data I get POST Forbidden (403) errors from my PHP script.
Here is the jsonlint.com
validated object I am working with which is generated from input elements and javascript-
{
"name": "Transfer Power",
"layout": "cic",
"artwork": "http://static.tvtropes.org/pmwiki/pub/images/Voyager_shield.jpg",
"rarity": "common",
"cost": "3",
"text": "Until the start of your next turn, target friendly Ship gains Shield +X and Damage -X where X is the Ship's current Damage."
}
From what I understand I should be able to send the complete artwork url
without any formatting but the POST only works when I remove the scheme of the url. I hope it's something simple. Here is the code-
var name = $('#name').val();
var layout = type;
var artwork = $('#artwork').val();
var rarity = $('#rarity').val();
var cost = $('#cost').val();
var type = $('#type').val();
var text = $('#text').val();
var card = {};
card.name = name;
card.layout = layout;
card.artwork = artwork;
card.rarity = rarity;
card.cost = cost;
card.text = text;
$.post('writecard.php', card, function(data){
console.log(data);
});
And the super simple PHP echo to re-verify my data-
<?php
$raw = $_POST;
foreach($raw as $key => $val){
echo $key . ': ' . $val . ' -- ';
}
?>
Again: It successfully sends the POST and returns the data when I remove the scheme of the URL.
One other point of concern: How do I ensure I'm sending integers and not characters? Should the "cost": "3",
not be shown, instead, as "cost": 3,
?
Thanks for reading. :]