# Problem with jquery ajax call and js.rjs code

**URL:** <https://www.ruby-forum.com/t/problem-with-jquery-ajax-call-and-js-rjs-code/172979>\
**Category:** Rails\
**Created:** [July 30, 2009, 6:56pm UTC](https://www.ruby-forum.com/t/problem-with-jquery-ajax-call-and-js-rjs-code/172979 "2009-07-30T18:56:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [July 30, 2009, 6:56pm UTC](https://www.ruby-forum.com/t/problem-with-jquery-ajax-call-and-js-rjs-code/172979/1 "2009-07-30T18:56:44Z")

</div>

On one of my pages, i make a remote request to the update action of my  
school\_subscribers controller with a jquery ajax call.

In my log, i can see that the action executes fine, and the  
corresponding js.rjs file is evaluated (i’m logging from inside that  
file and it all seems fine). I can see in the firebug console that i  
get a 200 back from the remote request. But, the code in the js.rjs  
file isn’t actually executed. I tried the simplest possible case of  
having it just do

page.alert(“hello”)

but no joy.

I think that this is just a problem with how i have my jquery ajax  
options set up - possibly the datatype option. I tried omitting  
datatype, and setting it to ‘script’, or ‘html’ but neither worked.

here’s my call:

```
function updateSubscriber(id, paramString){
  jQuery.ajax({
    async:true,
    type: "PUT",
    datatype: 'script',
    url: "/music_service/"+<%= @music_service.id

```

%\>+"/school\_subscribers/"+id,  
data: (paramString),  
error: function(msg){  
alert(“Sorry, there was an error updating this subscriber”);  
}  
});  
}

Can anyone see what i’m doing wrong? Should i be using an ajax call in  
this case?

---

<div class="post-metadata">

**Author:** ![cmaxvv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/85f322/32.png) [@cmaxvv](https://www.ruby-forum.com/u/cmaxvv)\
**Post date:** [July 31, 2009, 11:34am UTC](https://www.ruby-forum.com/t/problem-with-jquery-ajax-call-and-js-rjs-code/172979/2 "2009-07-31T11:34:29Z")

</div>

Even more maddening - i decided to try to do it with a button\_to\_remote  
instead:

\<%= button\_to\_remote “Mark as not paid”, :url =\>  
music\_service\_school\_subscriber\_path(@music\_service, subscriber,  
:school\_subscriber =\> {:paid =\> 0}), :method =\> :put, :failure =\>  
“alert(‘Sorry there was an error updating this subscriber’)” %\>

This generated the following, on the page (i added whitespace to make it  
more readable), which works, and appears to be exactly the same as i had  
when i hand-wrote the js! wtf? how come the code below works and the  
code above doesn’t?
