Note that there are some explanatory texts on larger screens.

plurals
  1. PORails Server Callback to different domain
    text
    copied!<p>I want to do the following: The client (from a different domain, right now a JQuery-Script on my local computer) sends a Ajax-Post to the server, the server saves the result to the server and sends HTML/text back to the client who injects it into his HTML.</p> <p>This is the Ajax-Call:</p> <pre><code> var params = '{"comment": "Test", "creator": "Prof Frick", "name": "Rainer", "url": "' + url + '"}'; alert(params); $.ajax({ type: "post", data: params, url: 'http://localhost:3000/pages/postjson/', success: function(data) { $('h1').html(data); } }); }); </code></pre> <p>This is my route:</p> <pre><code>match '/pages/postjson/' =&gt; 'pages#postjson' </code></pre> <p>And this is the controller:</p> <pre><code> def postjson parsed_json = ActiveSupport::JSON.decode(request.body.read) # @page = Page.where(:url =&gt; parsed_json["url"]) new_obj = Page.new new_obj.name = parsed_json["name"] new_obj.creator = parsed_json["creator"] new_obj.url = parsed_json["url"] new_obj.comment = parsed_json["comment"] new_obj.save render :json =&gt; @page[:name] end </code></pre> <p>I think my mistake is be quite basic and I really appreciate your help. My guess is that the mistake is either in </p> <pre><code> @page = Page.where(:url =&gt; parsed_json["url"]) </code></pre> <p>or in</p> <pre><code> render :json =&gt; @page[:name] </code></pre> <p>because everything goes through, the json-data gets saved, the browser even alerts "Success", but the I want to post to just disappears.</p> <p>Thanks for your advice. General coding tips also always appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload