I have a problem on cors in prolog. I think it not working.
Edit #1
:- module(server,[]).
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_cors)).
:- use_module(library(http/http_json)).
:- use_module(library(http/json_convert)).
:- use_module(library(option)).
:- use_module(library(settings)).
:- http_handler(root(.),handle,[]).
:- set_setting(http:cors, [*]).
server(Port) :-
http_server(http_dispatch,[port(Port)]).
:- json_object
poke(pokemon:text, move:text).
handle(Request) :-
format(user_output,"Request is: ~p~n",[Request]),
format(user_output,"Request2 is: ~p~n",[]),
cors_enable,
http_read_json_dict(Request, DictIn,[json_object(term)]),
format(user_output,"I'm here~n",[]),
term_string(Pokemon,DictIn.pokemon),
findall(poke(P,M),beat(P,M,Pokemon),L),
prolog_to_json(L,J),
format(user_output,"Pokemons are: ~p~n",[J]),
DictOut=J,
reply_json(DictOut).
beat(P,M,E) :-
pokerule:beat(P,M,E).
However I use ajax post to prolog server it said
XMLHttpRequest cannot load http://localhost:9999/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:1000' is therefore not allowed access. The response had HTTP status code 500.
Ajax that I use to post.
let enemyName = this.item.text
let data = {"pokemon":enemyName}
$.ajax({
url : END_POINT,
method : 'post',
contentType: 'application/json',
dataType : 'json',
data : JSON.stringify(data),
success : function (res) {
console.log(res);
},
error :function (res) {
console.log(res);
}
})
How can I solve this problem?
-Edited Now I fix some of my code but it still not work.