Forum Discussion

jonathancrow's avatar
14 years ago
Solved

How to redirect the response from a REST API Call

So close...

 

Ok I have a form that posts the content of a textarea to the body of a specific article. The problem is that after submitting the form, the browser displays the XML response from the REST API call.

 

The actual REST call works. I just need to take the response and either not display it or do something like redirect to the article page.

 

I tried appending: "&redirect_uri=${my_url}" to the API call but it didn't work.

 

Any suggestions?

 

More detailed code below...

 

thanks,

Jonathan

 

<form action="${my_community}/restapi/vc/messages/id/${my_topic_id}/reply?message.subject=${topic} method="POST" >
<p>
<textarea name="message.body" cols="80" rows="5"></textarea>
</p>
<p>
<label>
<input type="submit" value="Post Reply">
</label>
</p>
</form>

  • xorrkaz's avatar
    xorrkaz
    14 years ago

    Try this:

     

    <@liaAddScript>
    function handleSubmit(form) {
      ;(function($) {
        $.ajax({
          type: "POST",
          url: "${my_community}/restapi/vc/messages/id/${my_topic_id}/reply",
          data ({
            "message.body":form['message.body'].value,
            "message.subject":"${the_topic}"
          })
        });
      })(LITHIUM.jQuery);
    
      // note: my_url is a Javascript variable
      // use ${my_url} if your variable is in Freemarker
      window.location.href = my_url;
    }
    </@liaAddScript>

     

11 Replies

  • jonathancrow's avatar
    jonathancrow
    Advisor
    14 years ago

    Yeehaw!

     

    Ok here was the trick that worked:

     

    <@liaAddScript>
    function handleSubmit(form, my_url) {
    ;(function($) {
    $.ajax({
    type: "POST",
    url: "${my_community}/restapi/vc/messages/id/${my_topic_id}/reply",
    async: false,
    data: ({
    "message.body":form['message.body'].value,
    "message.subject":"${the_topic}"
    })
    });
    })(LITHIUM.jQuery);
    }
    </@liaAddScript>

     

    with a call from

     

    <form name="reply_form" action="${my_url}" onSubmit="handleSubmit(this); return true;">

     

    I don't know if it was the addition of the async, or there was a typo, or...

     

    But know you just got upgraded to a case!

     

    Thanks for everything.

     

    Jonathan