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!.

5
  • 1
    Post the php code as well. Commented Apr 4, 2013 at 21:22
  • 2
    The window.location is probably wrecking the POST. Commented Apr 4, 2013 at 21:25
  • check edit added php code Commented Apr 4, 2013 at 21:26
  • 1
    is the php code in effectsuploadify.php or handler.php Commented Apr 4, 2013 at 21:28
  • $val = file_get_contents( php://input ); Commented Apr 4, 2013 at 21:31

2 Answers 2

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,
});
Sign up to request clarification or add additional context in comments.

8 Comments

Did you remove window.location = "http://localhost/file/handler.php"; from after the script?
ok. I removed that. now it does not redirect how do i fix this.
Do you see any errors in the console?
I used the wrong method (tobase64)..Thanks alot..
oops! still getting the same error even after giving correct method name nothing in console. page redirects with undefines index error.
|
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();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.