0
我有一個REST風格的Web服務(Java),並且我想通過提交按鈕向Web服務發送獲取請求。如何通過javascript從HTML頁面調用REST風格的Web服務功能
在所謂的「測試」將從HTML頁面中的文本輸入一個字符串和返回一個字符串,然後我需要的字符串,並把它放在一個段落標記Web服務的功能無需刷新頁面
這裏是我的代碼:
HTML頁面:
<input type="text" id="equation_input">
<input type="button" value="Calculate" id="equation_submit" onclick="fun()">
<p id="value"></p>
RESTful Web服務:
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.tarek.doctorMath.resources.test.*;
@Path("/first")
public class first_equation {
@GET
@Path("/{test}")
@Produces(MediaType.TEXT_PLAIN)
public String test(@PathParam("test") String equation) {
return "test";
}
}
任何人都可以幫助我嗎?
fun()中會發生什麼?向我們展示代碼.. – juliobetta
請參閱:http://stackoverflow.com/questions/247483/http-get-request-in-javascript – sheunis