Enviar solicitud AJAX antes de Obtener rieles de solicitud

estoy enviando GET request with javascript window.open method and I need to pass array of some ids in it. So when I get URL like this:


But this is not acceptable. URL should not look like this. And I can't send the parameters through POST because my team lead denied it.

I wonder can I send an ajax request before my main GET request and pass array of ids with it, store it someway in my "new" method and use them when GET request is being sent? If it is possible how can I do this in rails? I other words I need to send my array with ajax request, store it somehow and use it when my actual GET request is sent. Thanks for replies.

preguntado el 04 de julio de 12 a las 08:07

2 Respuestas

You can serialize the data using JSON.

Entonces, si tienes:

var ids = [9,4,5,8];

Puedes usar esto:

var getString = "?ids="+JSON.stringify(ids);
var filePath = "whereYouAreSending";

Respondido 04 Jul 12, 08:07

This would make the url like "http://localhost:3000/controller_path/new?ids=[9,4,5,8]" And you should uri encode it and it will end up like "http://localhost:3000/controller_path/new?ids=%5B9%2C4%2C5%2C8%5D" - Esailija

It is not a solution but it makes URL look better. Thanks - Rafael Sedrakyan

definir un ruta with a controller method to handle the data

Respondido 04 Jul 12, 08:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.