0

I'm using ASP MVC and I'm trying to call a service that's on another one of my MVC websites.

I'm trying to use the following Ajax call.

function SomeFunction(decision) {
    if (decision == false)
        decision = "no";
    else
        decision = "yes";

    var input = {
        LogEventType:"PageView",                  
        CurrentPage: "invitation/?decision=" + decision + "&id=" + 32323,
    };
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "https://somewebsite.com/api/ClickStream/LogWebEvent/",
        data: JSON.stringify(input),
        crossDomain: true,
        dataType: 'jsonp',
        headers: {
            'Access-Control-Allow-Origin': '*'
        },
        success: function (data) {
            alert("We're awesome")
        },
        error: function () { console.log("Call to SomeFunction failed.") }
    });
}

I don't get any visible errors and I also put breakpoints on the service and inside of the success/error function of the ajax call but it never reaches any of them.

Anyone see where I messed up?

EDIT: Here is the Web Apis function I'm trying to access

[ActionName("LogWebEvent")]
[HttpPost]
public void LogWebEvent(ClickStreamEventDto data)
{
    try
    {
        _clickstreamLogger.LogWebEvent(data);
    }
    catch (Exception ex)
    {

    }
}

Where ClickStreamEventDto is

public class ClickStreamEventDto: Analytics.IAnalyticEventDto
{
    public string LogEventType { get; set; }
    public string CurrentPage { get; set; }
}
Kelsey Abreu
  • 1,094
  • 3
  • 17
  • 42

1 Answers1

0

When hitting cross domain sites, with either CORS or JSONP, make sure they are both HTTP or both HTTPS.

Make sure that when HTTPS is involved, that both site's certificates have been accepted. You may need to hit the HTTPS site in another window, and accept the certificate if there is no trust relationship to the issuer.

Justice Fist
  • 111
  • 4