是否可能使用JSF提供的spring引导api rest?
我尝试从xhtml文件执行ajax查询,其trows错误为: 未捕获的语法错误:无效或意外标记 这是我的ajax查询:是否可能使用JSF提供的spring引导api rest?,rest,api,spring-boot,jsf,Rest,Api,Spring Boot,Jsf,我尝试从xhtml文件执行ajax查询,其trows错误为: 未捕获的语法错误:无效或意外标记 这是我的ajax查询: <h:form> <script type="text/javascript"> llamadaNombre(); function llamadaNombre(){ var list2=null; $.ajax({ type : "
<h:form>
<script type="text/javascript">
llamadaNombre();
function llamadaNombre(){
var list2=null;
$.ajax({
type : "GET",
url : "localhost:8080/users",
dataType: "json",
data: {val: list2},
success : function(result) {
$('#tablebody').html("");
$.each(result,function(key, val) {
editar="<h:commandLink action='/paginas/crud/editarCliente?dni="+val.dni+"' class='btn btn-success'> <span class='glyphicon glyphicon-search'></span> editar </h:commandLink>" ;
eliminar="<h:commandLink action='/paginas/crud//eliminarCliente?id="+val.dni+"' class='btn btn-success'> <span class='glyphicon glyphicon-trash'></span> eliminar </h:commandLink>";
var htmlrow ="<tr>"+"<td>" + val.id + "</td>"+"<td>" + val.nombre + "</td>"+"<td>" + val.apellidos + "</td>"+"<td>" + val.dni + "</td>"+"<td>" + val.correo + "</td>"+"<td>" + val.telefono + "</td>"+"<td>" + val.direccion + "</td>"+"<td>" + val.cp + "</td>"+"<td>" + val.edad + "</td>"+"<td>" + editar + "</td>"+"<td>" + eliminar + "</td>"+"</tr>";
$('#tablebody').append(htmlrow);
})
}
})
}
</script>
</h:form>
我尝试在不同的环境中更改端口,但它会不断返回该错误,如果在相同的端口trows错误中配置,则该端口将其侦听
这是我的API控制器:(已解决)
@服务
@交叉原点(原点=”http://localhost:8080")
公共类用益控制人{
公共列表getAll(){
return clientsfacade.getAllClients();
}
您应该将headers参数作为以下脚本添加到请求中:
$.ajax({
type : "GET",
url : "localhost:8090/users",
data: {val: list2},
headers: {
"X-Requested-With": "XMLHttpRequest",
"Authorization": .......,
},
success: function (data, text) {
console.log(data);
},
........
在您的java控制器中,您应该授权从localhost访问。在您的情况下,您只需将注释:
@crossorigin(origins=“localhost”)
添加到您的服务中。这与jsf有何关系?jsf运行在服务器端,javascript客户端我必须激活浏览器应用程序以实现交叉自动化
@Service
@CrossOrigin(origins = "http://localhost:8080")
public class UsuariosController {
public List<Clientes> getAll(){
return clientesFacade.getAllClientes();
}
$.ajax({
type : "GET",
url : "localhost:8090/users",
data: {val: list2},
headers: {
"X-Requested-With": "XMLHttpRequest",
"Authorization": .......,
},
success: function (data, text) {
console.log(data);
},
........