November Happy Hour will be moved to Thursday December 5th.

ajax post call to epi server block controller not working

Vote:
 

I am trying to send an ajax POST request from javascript (razor view ) to epi server block controller, it is not hitting. I am only to able to send GET request. Below is the code snippet for controller for javascript

 $.ajax({            url: '/BreadcrumbAndSharing/SendEmail/',            type: 'GET',            data: JSON.stringify({                name: "Tommy",                birthday: new Date(1921, 0, 1),                hobbies: ["Pinball", "Holiday camp"]            }),            contentType: 'application/json',            error: function (xhr) {                alert('Error: ' + xhr.statusText);            },            success: function (result) {                CheckIfInvoiceFound(result);            },            async: true,            processData: false        });

public ActionResult SendEmail(Person person)
{

Object obj = JsonConvert.DeserializeObject(Request.Params[0].ToString());
Person objperson = JsonConvert.DeserializeObject(Request.Params[0].ToString());
string subject = "test email";
string body = "testing this email";

}

Any help is higly appreciated in this regard

#114890
Dec 30, 2014 7:47
Vote:
 

First:
Change this_:
$.ajax({            url: '/BreadcrumbAndSharing/SendEmail/',            type: 'GET'

To
$.ajax({            url: '/BreadcrumbAndSharing/SendEmail/',            type: 'POST'

And then decorate your action with this

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SendEmail(Person person)

{

#114897
Dec 30, 2014 13:56
Vote:
 

Thanks, i did tried these options as already. Code shared is for GET request, whcih is working POST is not working at all. if you track it in fiddler  it says HTTPS status code 301 got POST and then after that it issue a GET request automatically which says 404, (which is obvious i think becuase action is decorated with POST attribute)

#114904
Dec 31, 2014 5:39
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.