I have a Sinatra app and there is an ajax method in it. Previously it returns 200 and result. Now it starts returning 302 and result as which is still correct (I can see that in Google Chrome debug console).
Here is the xaml code:
:javascript
$(document).ready(function() {
$(document).on("click", "#my_id", function(){
$.ajax({
type: "GET",
url: "/my_url",
success: function(data){
window.location = data;
}
});
});
});
def my_url
#getting a data.....
#returning the data... there is nothing unusual
end
UPDATE:
That’s what I did:
def my_url
result = get_result()
response.headers['Location'] = request.referer
result
end
but Location header in Response has not been changed and the error is remaining.
302 is not an error code. It’s the HTTP status code for a redirect which you are doing by adding a
Locationheader. Adding theLocationheader automatically changes the status code to 302. The only type of expected response for a 302 is something that a browser that doesn’t understand a 302 will see. For example, an HTML page explaining that it is a redirect with a link to the new page. For AJAX no response is expected for a 302 and the browser will fetch the results of the new location you are redirecting to.See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.3 for more details about HTTP status codes.