ajax - dojo.xhrpost getting status code as 0 -
I'm submitting a to dojo using xhrpost. My app runs on Ruby on Rails in a controller I I'm performing the redirect. I send a reservation header to the redirect URL. I use the redirect URL on the client and then load the redirect URL to the client. The following is the code.
In the scene, dojo.xhrpost submit using ajax
function () {var form = dojo.byId ("form_id"); Dojo.connect (form, "onsubmit", function) {// stop off event, since we want to control form submissions Dojo.stopEvent (event); var xhrArgs = {form: dojo.byId (" Form_id "), HandleAs:" text ", Load: function (data, ioargs) {redirect to url; // redirect URL redirected from {// response header var new_url = ioargs.xhr.getResponseHeader (" new_url ") . Location.href = New_url;}, Error: function (response) {// handling error}} // submit to deferred = dojo.xhrPost (xhrArgs);}} for the action 1; }
Code in Controller
def action1 new_url = url_for (: controller => "controller",: verb = & Gt; "Action 2") in Redirection redirection while tracking the new URL as the parameter: Action 2 ,: new_url = & gt; Receive the new URL from the New_url and DEF Action 2 # Params and save it to the Rion headers so that it can be accessed in the client response. [[New_url]] = Parameters [: new_url] End
It worked fine on my local host but when I put it on my server it failed.
I'm getting ioargs.xhr.status "0". The data is "" though the saved response to this form is empty and no response headers are set.
Please help.
I had to change the controller a bit. def 1 Action if request.xhr? Render: Jason = & gt; New_url.to_json else #follow normal redirection redirect_to: action2 end also in the AJAX call
var xhrArgs = {form: dojo.byId ("form_id" ), Handle: "json", load: function (data, ioargs) {// data redirected url from document. place. Html = data; }, Error: function (response) {// handling error} Actually I did not return the correct HTML page as a response in the right way.
The URL should be returned in response and should be viewed from the View, .
Comments
Post a Comment