bigskysoftware/intercooler-js

ic-on-success execute before response header X-IC-Set-Local-Vars

prhost opened this issue · 1 comments

Hello people,

I would like to update an input hidden with a value that comes from ajax, I'm trying via lX-IC-Set-Local-Vars, and in ic-on-success I get the localStorage and update the input value via jquery , the problem is that on-success is running before processing the X-IC-Set-Local-Vars header. Is there a better way to return an information and use it besides the target in html?

My scenario is as follows:

I have a registration form, when I successfully save it, I run ic-push-url updating my /create url to /update?id=123 a problem that ic-post-to is running the /save method needs to pass that ID to /save, or find another way to resolve it.

please, helpme 😔

1cg commented

I would recommend triggering a client side event using the X-IC-Trigger header instead of going through the local var stuff. Seems more direct.

If you look in the responses section of the tocs, there is an example that shows how this is done, and it passes an argument to the event:

http://intercoolerjs.org/docs.html#responses

search for 'Invoke the' and then view the code for that button:

            $(function(){
              $('#trigger_demo').on('myEvent', function (elt, arg) {
                alert("myEvent was invoked by a response header with arg: " + arg + "!"); //wire in an event handler
              });
            });
            $.mockjax({
              url: '/trigger_demo',
              headers: {"X-IC-Trigger": '{"myEvent":["foo"]}'}
            });

you could have an event like setMyHiddenVal and then use the value '{"setMyHiddenVal":["whatever"]}'}

hope that helps