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