1

I used base64 encoded to display image dynamically (by select image).

<img style="width: 412px;" src="data:image/gif;base64,R0lGODlhwAAAAXAAACH5BAEAAPwALA

How to send image to a server? by $.ajax() and without postback.

Thanks in advance

1 Answer 1

2
$.ajax({
    type: 'POST', //or get
    url : 'urlToMyServer.aspx',
    data: { img : $('img').attr('src') }
});

If the B64 is'nt really, really long, just send it the regular way ?

Sign up to request clarification or add additional context in comments.

12 Comments

data: $('img').attr('src') this won't work. data accepts an object or a query string.
@iMoses it accepts arbitrary string, which jQuery will send literally as POST request body
@iMoses - sending a string is'nt a problem, but objects are actually easier to understand in this case I think, so I've edited it.
If so than how do I fetch it on the server side? What's the name of my post variable? As far as I know, if you wanna use a string it should be formated as a query string, such as: data: 'img=' + $('img').attr('src')
If you pass a string, jQuery will not do anything to it, and you have to parse raw request body manually on the server
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.