# Ajax, jQuery

**URL:** <https://www.ruby-forum.com/t/ajax-jquery/189676>\
**Category:** Rails\
**Created:** [June 4, 2010, 9:41pm UTC](https://www.ruby-forum.com/t/ajax-jquery/189676 "2010-06-04T21:41:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [June 4, 2010, 9:41pm UTC](https://www.ruby-forum.com/t/ajax-jquery/189676/1 "2010-06-04T21:41:10Z")

</div>

I am not sure where I should post this since this seems to be an  
“interdisciplinary” problem

I am having trouble communicating between my javascript and my Rails  
app.

Here’s the snipped of code from my controller

* * *

def poll  
p params  
puts “Got here:”  
# debugger  
@some\_object = 12345  
respond\_to do |format|  
format.json { render :layout =\> false, :json =\> @some\_object }  
end  
end

* * *

I see

* * *

{“comment”=\>“ch”, “_method"=\>“PUT”, “action”=\>“poll”,  
“controller”=\>“reviews”, "_”=\>“1275680223825”}  
Got here:

* * *

in the Webrick console log

Here’s the relevant javascript:

* * *

pollWithAjax = function() {  
$.ajax(  
{  
// Define AJAX properties.  
type: “GET”,  
url: “/poll”,  
dataType: “script”,  
data: { \_method: ‘PUT’, “comment”: ‘ch’ },  
timeout: (10 \* 1000),  
beforeSend: function(xhr) {xhr.setRequestHeader(“Accept”,  
“application/json”)},

```
  // Define the succss method.
  success: function(){
    alert('pollWithAjax Success')
  },

  // Define the error method.
  error: function( objAJAXRequest, strError, errorThrown ){
    alert("pollWithAjax Error! Type: " + strError);
  }
}

```

);  
};

* * *

The “error:” function returns with the value of strError being “error”.

This is what FireBug says my headers look like

* * *

Response Headersview source  
Request Headersview source  
Host localhost:3000  
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3)  
Gecko/20100401 Firefox/3.6.3 ( .NET CLR 3.5.30729)  
Accept application/json  
Accept-Language en-us,en;q=0.5  
Accept-Encoding gzip,deflate  
Accept-Charset ISO-8859-1,utf-8;q=0.7,\*;q=0.7  
Keep-Alive 115  
Connection keep-alive  
X-Requested-With XMLHttpRequest  
Referer [http://localhost:3000/products/1](http://localhost:3000/products/1)  
Cookie  
\_store\_session=BAh7CDoPc2Vzc2lvbl9pZCIlZDZhNDMyMjI2OTNhMTAzNTQxZjVmNTA5MDIwOTc1MDUiCmZsYXNoSUM6J0FjdGlvbkNvbnRyb2xsZXI6OkZsYXNoOjpGbGFzaEhhc2h7AAY6CkB1c2VkewA6EF9jc3JmX3Rva2VuIjFnREJwbW9Oam02NFArWWxla1dXUE1OMmk2eU9EUk9lWnhDMDF4WHA0QUtFPQ%3D%3D–582cb4d8997a9876030fa55e15d37e12177b02db

* * *

When I click on the response tab in Firebug, I see nothing.

Am I setting up the headers incorrectly?

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [June 4, 2010, 10:35pm UTC](https://www.ruby-forum.com/t/ajax-jquery/189676/2 "2010-06-04T22:35:01Z")

</div>

Ralph S. wrote:

> I am not sure where I should post this since this seems to be an  
> “interdisciplinary” problem
> 
> I am having trouble communicating between my javascript and my Rails  
> app.

[…]

## Now that you’ve shown us your code, please explain how the actual behavior of your app differs from what you want it to do. Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ralphshnelvar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e19adc/32.png) [@ralphshnelvar](https://www.ruby-forum.com/u/ralphshnelvar)\
**Post date:** [June 4, 2010, 11:16pm UTC](https://www.ruby-forum.com/t/ajax-jquery/189676/3 "2010-06-04T23:16:54Z")

</div>

Marnen Laibow-Koser wrote:

> Ralph S. wrote:
> 
> > I am not sure where I should post this since this seems to be an  
> > “interdisciplinary” problem
> > 
> > I am having trouble communicating between my javascript and my Rails  
> > app.
> 
> […]
> 
> ## Now that you’ve shown us your code, please explain how the actual behavior of your app differs from what you want it to do. Best,
> 
> Marnen Laibow-Koser  
> [http://www.marnen.org](http://www.marnen.org)  
> removed\_email\_address@domain.invalid

I would like a success return and the data returned.

The return is now taking the error return.
