jquery - Ajax return not passing Data, rails -


okay, i'm sure simple i'm running out of hair pull out. i'm posting ajax request controller , trying response in coffeescript. tried moving pure js, didn't make difference.

the jquery document implies newimage() should newimage(data) if error data undefined. code undefined alert.

jquery ->   $('select[data-type=scene]').change ->   i_num= $(this).attr('data-num').tostring()   i_value= $(this).find(':selected').text()   request= 'new image :'+ i_num + ': :' + i_value  + ': image'   $.post('/new_image', {request: => request}, newimage())  newimage= (new_url) ->   alert new_url 

the controller providing response can see in console, ajax callback doesn't seem grab it. controller code .

 def new_image    request= params['request'].split(':')    @url= get_thumb_url(request[3])    @img_num= request[1]    reply= @img_num + '::' + @url    render json: reply, content_type: 'text/json'  end 

the response 3::https://bnacreations.s3.amazonaws.com/g/thumbnails/image.jpg

any suggestions of i'm off track?

this calls newimage function while building argument list $.post:

$.post('/new_image', {request: => request}, newimage()) # --------------------------------- function call --^^ 

if want give $.post reference function (which want do), leave off parentheses. also, $.post wants data in second argument whereas request: => request has function value request. want instead:

$.post('/new_image', { request: request }, newimage) 

the => (fat-arrow) in coffeescript defining bound function, isn't ruby-style hashrocket building hashes.

btw, coffeescript has ruby-ish string interpolation can say:

request = "new image :#{i_num}: :#{i_value}: image" 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -