I’m having issues with jquery’s $.post function, and (what I think) the cross-domain security thing.
The weird part is that the page I’m trying to post to, is in the same directory as the page that sends the post.
This is the javascript code of ‘latest.php’, the file that makes the post request:
$.post("upload.php", { base64: fCanvas, description: description }, function(data){
// some things happen here
});
upload.php is a php script that uploads the content of the base64 variable to Tumblr.
The javascript console shows a 403 Forbidden error. I tried chmodding -777 ‘upload.php’, but that didn’t change anything.
Using $.get instead of $.post works, but is undesired due to security reasons, and the length limit of $get data (I’m sending a base64 encoded image).
EDIT: I changed one of the $.get requests on ‘latest.php’ to a $.post one, and it’s working…
$.post("base64.php", { url: t_url },
function(data){
data = "data:image/gif;base64,"+data;
draw(data);
});
So, I’m completely clueless of what’s going wrong.
Well. I got it working.
I tried sending a smaller (still base64-encoded) image to my upload.php script, and it did the job. It appears that jQuery’s post function can’t handle large (thats relative, it’s just a 640×453 image) amounts of data.
I solved the problem by using a XMLHttpRequest() instead. It works like a charm.
If anybody knows the exact problem with jQuery’s Ajax, please let me know, because I still don’t know exactly why my data caused a HTTP Forbidden error.