1

I want to send a javascript variable which contains an image base64 (png) value (Too big for GET requests). How do i send this base64 value to the php page (POST request) so as to decode base64 and then save it.

var base64 = this.tobase64(); // store base64 value to this variable

        $.post('/js/uploadify/handler.php', {basevalue: base64});

                });

    window.location = "http://localhost/file/handler.php";

I tried the above code but it does not work,

I want to send the value with an onclick event on a button (which is not a submit button). I am not using forms.

PHP CODE

$val = $_POST['basevalue'];
echo $val;

I get Notice: Undefined index: basevalue error

thanks!.

user1910290
  • 537
  • 4
  • 15
  • 28

2 Answers2

2

Wait for a success on $.post().

function wl(){
 window.location = "http://localhost/file/handler.php";
}
var base64 = this.tobase64(); // store base64 value to this variable
$.post('/js/uploadify/effectsuploadify.php',{
  basevalue: base64,
  success: wl,
});
Alex W
  • 37,233
  • 13
  • 109
  • 109
Mooseman
  • 18,763
  • 14
  • 70
  • 93
0

POST only sends the value of form's feilds to next page. In order to send your image to next page, assign it to value of hidden feild and submit form using java script.

var form = document.createElement("form");
form.setAttribute("method", "POST");
form.setAttribute("action", "http://localhost/file/handler.php");

var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", "image");
hiddenField.setAttribute("value", base64);

form.appendChild(hiddenField);
document.body.appendChild(form);
form.submit();