Call Server action through javascript and get Input Data Value

Call Server action through javascript and get Input Data Value

  

Hi,

  I am currently working on a functionality, in a link by using javascript code i am uploading an image,after that i want to call a server action through javascript code and get the uploaded image content.

So,How can I call a server action by using javascript code and get the uploaded image content.

Can anyone please help me?

Thanks.

Hello Pratima. 

If this is related with the "default image" in the other topic, I suggest you a different approach.
Use two image widgets (in a screen IF) and if the URL one fails, use your javascript to click a hidden link and call an action (ajax submit) and change the condition to show the alternative image, refreshing the IF.

Cheers,
Eduardo Jauch

Pratima, is this Mobile or Web?

When you say you're "uploading an image", do you mean you're using an Image Widget?

Lastly, if you've got the image client-side... why do you want to go get it from the server?

I have something in mind, but just wanted to get a bit of info.

Eduardo Jauch wrote:

Hello Pratima. 

If this is related with the "default image" in the other topic, I suggest you a different approach.
Use two image widgets (in a screen IF) and if the URL one fails, use your javascript to click a hidden link and call an action (ajax submit) and change the condition to show the alternative image, refreshing the IF.

Cheers,
Eduardo Jauch

Hi Eduardo,

It is not related with the "default image"  topic.

Actually,I have taken a link with extented Property onclick added javascript code for uploading an image by using Image Widget.

"$('#"+Upload1.Id+"').click();
document.getElementById('"+ Upload1.Id +"').onchange = function () {
  var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '')
$('#"+ FileName.Id +"').text(filename);
$('#"+UploadHiddenButton.Id+"').click();
};"

I used above code for uploading an image and after that I am calling an action(with ajax submit method) through uploadHiddenButton,In action i am not getting the values of uploaded image?

Is there any another way to get the values?



Davidk wrote:

Pratima, is this Mobile or Web?

When you say you're "uploading an image", do you mean you're using an Image Widget?

Lastly, if you've got the image client-side... why do you want to go get it from the server?

I have something in mind, but just wanted to get a bit of info.


Hi Davidk,

It's a Web App.

I am using image widget only.

Actually,I have taken a link with extented Property onclick added javascript code for uploading an image by using Image Widget.

"$('#"+Upload1.Id+"').click();
document.getElementById('"+ Upload1.Id +"').onchange = function () {
  var filename = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '')
$('#"+ FileName.Id +"').text(filename);
$('#"+UploadHiddenButton.Id+"').click();
};"

I used above code for uploading an image and after that I am calling an action(with ajax submit method) through uploadHiddenButton,In action i am not getting the values of uploaded image?

Is there any another way to get the values?

Sorry to keep asking... but I want to understand what you are doing... and why... only to give me insight as to what could be done.

Do you want to upload an image to the server... and then have that image displayed in your Image Widget?

Or do you want to replace the image displayed in the Image Widget?

You say you want to upload an image... and then get that image content.  What you are going to do with that content once you have it?  Is it always the same image you are uploading... or different images?

Davidk wrote:

Sorry to keep asking... but I want to understand what you are doing... and why... only to give me insight as to what could be done.

Do you want to upload an image to the server... and then have that image displayed in your Image Widget?

Or do you want to replace the image displayed in the Image Widget?

You say you want to upload an image... and then get that image content.  What you are going to do with that content once you have it?  Is it always the same image you are uploading... or different images?

Hi Davidk,

Yes, I want to upload an image to the server... and then have that image displayed in your Image Widget.Sorry I am using the uploading word again and again which confused you i think my mistake.

Thanks.

Hi Pratima.

I don't know if you really need JavaScript to do what you want...
In any case, I think the upload of the image only works if the button/link that calls the action is set to Submit (Ajax Submit does not work).

Also, remember that your image widget will require a file name.
If you use a fixed file name, the browser will cache the first image and for the duration of the cache will not display a new image. To avoid this problem, when changing an image, add to the name of the image something that identify it uniquely and identify the date/time in which it was uploaded.

Cheers,

Eduardo Jauch