# Rendering the response to the javascript

**URL:** <https://www.ruby-forum.com/t/rendering-the-response-to-the-javascript/141176>\
**Category:** Rails\
**Created:** [June 23, 2008, 9:56am UTC](https://www.ruby-forum.com/t/rendering-the-response-to-the-javascript/141176 "2008-06-23T09:56:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [June 23, 2008, 9:56am UTC](https://www.ruby-forum.com/t/rendering-the-response-to-the-javascript/141176/1 "2008-06-23T09:56:36Z")

</div>

We are working on the application where we need to call the scanner  
device  
to scan the image. We use DynamicWebTwain. Using the  
‘HTTPUploadThroughPost’  
method we upload the image to the URL. It’s all fine.

We need to return the saved image id from the controller action  
as Http response. How to send the Http response back to this javascript?

function btnUpload\_onclick(court\_id)  
{  
var strActionPage;  
var strHostIP;

```
  var CurrentPathName = unescape(location.pathname);
  var CurrentPath = CurrentPathName.substring(0,

```

CurrentPathName.lastIndexOf("/") + 1);  
strActionPage = CurrentPath +  
“court\_images/save\_image?court\_id=”+court\_id;  
frmScan.DynamicWebTwain1.HTTPPort = 3000;  
frmScan.DynamicWebTwain1.HTTPUploadThroughPost(“localhost”, 0,  
strActionPage, “imageData.pdf”);  
if (frmScan.DynamicWebTwain1.ErrorCode != 0) {  
alert(frmScan.DynamicWebTwain1.HTTPPostResponseString);  
}  
else  
frmScan.submit();  
}

---

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [June 24, 2008, 7:00am UTC](https://www.ruby-forum.com/t/rendering-the-response-to-the-javascript/141176/2 "2008-06-24T07:00:07Z")

</div>

Can some one in the group help me out for this issue…

Thanks.  
Ratnavel

---

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [June 25, 2008, 9:09am UTC](https://www.ruby-forum.com/t/rendering-the-response-to-the-javascript/141176/3 "2008-06-25T09:09:20Z")

</div>

I may be naive in this area, but it is not entirely clear to me how  
this interacts with Rails, which may be why you have not had a reply.

It appears to me that the javascript runs from the browser, pulling  
the image data from the TWAIN server and you then post it to the Rails  
App. If that is correct, then does can the rails action that receives  
the request with the image data not return the id to the browser.

Is it not the frmScan submit that sends a standard post request with  
the data to the Rails app?

Sorry this is a question rather than an answer, but it may help get  
the ball rolling so that someone else may also be able to help.

Tonypm

---

<div class="post-metadata">

**Author:** ![ayyanar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/82dd89/32.png) [@ayyanar](https://www.ruby-forum.com/u/ayyanar)\
**Post date:** [June 25, 2008, 10:21am UTC](https://www.ruby-forum.com/t/rendering-the-response-to-the-javascript/141176/4 "2008-06-25T10:21:24Z")

</div>

Could that be done with RJS?

Set the ID in the controller method (e.g. @id = image.id) and than  
pass it to the JS function in the RJS.

page.call(“btnUpload\_onclick”, @id)

On 23 Jun., 09:56, Ayyanar Aswathaman \<rails-mailing-l…@andreas-
