我想$.ajax从外部 ASP.NET MVC 站点(在本例中 - 从我的站点)检索一些数据。下面的代码给了我一个404 Not Found error(当然url是有效的。
但是,如果我将 url 从更改url: 'http://myurl.com/Home/GetMyCode/?id=mycode'为url: 'http://localhost:123/Home/GetMyCode/?id=mycode'一切都很好。那么,如何解决呢?
 $.ajax({
        url: 'http://myurl.com/Home/GetMyCode/?id=mycode',
        type: 'POST',
        contentType: "application/json; charset=utf-8",
        crossDomain: true,
        success: function (res) {
            ...
        },
        error: function (jqXHR, textStatus, errorThrown) {
            ...
        }
    });
    [HttpPost]
    public JsonResult GetMyCode(string id)
    {
        try 
        {
            return Json(new { result = "ok", resultData = "OK") });
        }
        catch (Exception e)
        {
            return Json(new { result = "error", resultData = "An error occured" });
        }            
    }