java中调用ajax返回html格式

1.在jsp页面中<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK"%> Inser here//回调函数function callback(data){ $("#checkmenunamespan").html(""); $("#c
摘要由CSDN通过智能技术生成

1.在jsp页面中

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@ taglib uri="webwork" prefix="ww" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<title>Inser here</title>
<script src="/js/jquery-1.8.1.js" type="text/javascript"></script>
<script type="text/javascript">

//回调函数
function callback(data){
    $("#checkmenunamespan").html("");
    $("#checkmenunamespan").html(data);
}

function search(id){
     var parentName = id;
     var params = "aboutId=" + parentName;
    $.ajax({
       type:
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用 AJAX 调用 Java Web Service,需要执行以下步骤: 1. 创建一个 Java Web Service,可以使用 JAX-WS 或 Apache Axis 等框架。 2. 在 Web 服务端口上启用 RESTful Web 服务。 3. 在客户端页面使用 AJAX 发送 HTTP 请求。 4. 在服务端编写代码来处理请求并返回响应。 下面是一个示例代码: Java Web Service: ```java package com.example; import javax.jws.WebMethod; import javax.jws.WebService; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; @WebService @Path("/hello") public class HelloService { @WebMethod @GET @Produces(MediaType.TEXT_PLAIN) public String sayHello() { return "Hello, World!"; } } ``` 客户端 HTML 页面: ```html <!DOCTYPE html> <html> <head> <title>AJAX Example</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <button id="btn">Say Hello</button> <div id="result"></div> <script> $(document).ready(function() { $("#btn").click(function() { $.ajax({ url: "http://localhost:8080/HelloService/hello", type: "GET", dataType: "text", success: function(response) { $("#result").text(response); }, error: function(xhr, status, error) { $("#result").text("Error: " + error); } }); }); }); </script> </body> </html> ``` 在这个例子,我们使用 JAX-WS 框架创建了一个简单的 Web 服务,它返回一个字符串 "Hello, World!"。然后,在客户端 HTML 页面使用 jQuery 发送一个 AJAX 请求,请求这个 Web 服务,并将响应显示在页面上。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值