正在尝试触发application-1的Post方法并在新窗口或新标签页中打开。
Application-1
public class TestController : Controller
{
[HttpPost]
public ActionResult PostSearch(object searchInput)
{
return RedirectToAction("Index", "Studnet")
}
}
想要从application-2触发此post方法。
<input type="button" id="search"
value="Trigger Post" onclick="TriggerPostSearch('1234')"/>
function TriggerPostSearch(searchObject) {
var url = "http://www.localhost:99/test/PostSearch";
OpenWindowWithPost(url, searchObject);
};
function OpenWindowWithPost(url, model) {
var param = { "searchInput": model };
$.ajax({
url: url,
type: "POST",
contentType: "application/json",
data:param
}).done(function(result){
window.open(url, '_blank');
});
}
在app-1中启用CORS以接受来自app-2的请求。还有其他方法吗?