jQuery Ajax call to F#?

北城以北 提交于 2019-12-12 03:56:15

问题


Is there any way to make a call to an f# library using jQuery without having to wrap it into a web service method?


回答1:


As mentioned in comments, you could translate F# to JavaScript. This is actually pretty doable, because it can use quotations (a high-level representation of F# code). There are two projects that do this. One is a rather sophisticated commercial project named WebSharper (which has other features too) and the other one is open source project FSharp.Javascript.

If you want to avoid web services, you can also write a simple HTTP server. This would be a standalone application that you can run on your server and it will directly handle requests. I did that using HttpListener class in a recent talk in London. You can find the sample here.

There are definitely other ways - if you're working in ASP.NET application, then you can use HttpHandler or a page written in F# that will just handle the request directly. It is probably easier to have the main front-end as a C# project, but you can write the page/handler in F# and just reference it or inherit from it in C# (example using ASP.NET MVC is here).




回答2:


You could write a HttpHandler as a wrapper.



来源:https://stackoverflow.com/questions/4414942/jquery-ajax-call-to-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!