views:

66

answers:

2

I'm looking to take data posted to a form, process it and then make a redirect to a third-party website with both GET data AND POST data.

I understand that Response.Redirect() is not the way to go about this - what is though?

I dont want to make the original form submit to the third party provider, I have some processing to do on their results first - so that's not an option.

Can anyone recommend a way for me to pass the user along to the 3rd party provider (outside of my domain)?

A: 

html

<form id="aForm">
     name: <input type="text" id="userName">
</form>
<script type="text/javascript">
jQuery.ajax({
     url:'Home/FistAction',
     data:jQuery('#aForm').serialize(),
     type:'POST'
     success:function(data){
           // it would make more sense if received data is of type json
           // pass this data to third party, with jsonp request type
     }
});
</script>


    [HttpPost]
    public JsonResult FistAction(FormCollection f)
    {
       // process your form and creat new object 'NewObject'        

       //return json to make third party request
       return Json(NewObject,JsonRequestBehavior.DenyGet)
    }
Praveen Prasad
Hi Praveen, will this allow me to redirect my user to a website outside of my domain/server?
John Smith
i have re-edited my code.please check it
Praveen Prasad
So the best method is to make a new form with the post-processed values and use javascript to force submit the form once it's rendered?Is there not a server-side way of doing this? This method seems a bit ...fudged?
John Smith
u dont have to make one more form but have to return data(which u want to pass to third party) as json. when that data is received back from u have to pass that data to third party. u can also make a network call in "Fisrt_Action" method to post ur data to third party server. i have not written that as most most webhosting companies dont allow that.
Praveen Prasad
You mention 'creat new object 'NewObject'' -> what type of object is NewObject?
John Smith
newObject is any object that u want to pass to third patry
Praveen Prasad
Forgive me If i'm missing something, but where do I specify the 3rd Party's web-address?
John Smith
if u are making 3rd party request through ajax then in "success" function in javascriot code. And if you want to make call through server side code, then inside Action methods. like this::: public ActionResult MyAction(FormCollection f) {make network call; return View("saying_successful/error")}
Praveen Prasad
A: 

Typically (barring the use of web services), this is done by doing whatever processing you need, and then GETting or POSTing the data to the third party site. They would then POST or GET back at a later time (making this an asynchronous operation), to a pre-arranged URL on your site, or one that you pass along to them, allowing you to do whatever you want with their output.

RedFilter