① spring boot 整合的webservice 怎麼用js調用
其實這二者的整合十分的簡單,比以前xml的方式更加的簡潔,
js調用代碼如下:
$.ajax({
url : ActionUrl,
type : "GET",
dataType : "json",
async : false,
data : {
id: "id"
},
success : function(data) {
成功處理數據;
}
});
② js調用 webservice等介面時,怎樣解決調用時的json跨域問題(在不用jsonp的情況下)
model' => $model, // Your model
attribute' => 'news_date', // Attribute for input
options' => array(
dateFormat' => 'yy-mm-dd',
changeYear'=> 'true',
changeMonth'=> 'true',
yearRange'=> '1900:2099',
showOn' => 'both',
buttonText' => 'Click',
)
③ javascript怎麼調用webconfig中的參數急求!
1.在web.config中:
<appSettings>
<add key ="url_house" value="hid"/>
</appSettings>
2.在urlHouse.aspx.cs中:
public string url_house;
protected void Page_Load(object sender, EventArgs e)
{
url_house = ConfigurationManager.AppSettings["url_house"];
}
3.在urlHouse.aspx中:
<head runat="server"><title>結果顯示</title>
<script language="javascript" src="js/urlHouse.js" type="text/javascript"></script>
<script language="javascript">
function Init_urlHouse()
{
url_house="<%=url_house%>";
}
</script>
</head>
<body onload="Init_urlHouse();">
..........
4.在urlHouse.js中:
alert(urlHouse);
④ Js如何調用webservice
要想實現JS調用WebService,可以按如下步驟實現(經過測試):
第一步:創建一個WebService
在此處我就創建了一個默認的web服務,並不做什麼修改,把主要集力放在怎麼實現JS調Web服務上面。
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
/// <summary>
///WebService 的摘要說明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//如果使用設計的組件,請取消注釋以下行
//InitializeComponent();
}
[WebMethod]
public string HelloWorld()
{
return "Hellow World";
}
}第二步:創建一個頁面,實現JS調用Web服務
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function RequestWebService() {
//這是我們在第一步中創建的Web服務的地址
var URL = "http://localhost/YBWS/WebService.asmx";
//在這處我們拼接
var data;
data = '<?xml version="1.0" encoding="utf-8"?>';
data = data + '<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">';
data = data + '<soap12:Body>';
data = data + '<HelloWorld xmlns="http://tempuri.org/" />';
data = data + '</soap12:Body>';
data = data + '</soap12:Envelope>';
//創建非同步對象
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.Open("POST", URL, false);
xmlhttp.SetRequestHeader("Content-Type", "application/soap+xml");
xmlhttp.Send(data);
document.getElementById("data").innerHTML = xmlhttp.responseText;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="One" type="button" value="JsCallWebService" onclick="RequestWebService()" />
</div>
<div id="data">
</div>
</form>
</body>
</html>
⑤ java app或java web實現調用遠程JS和webservice的思路
使用windows定時任務運行批處理程序(bat)打開固定頁面來實現定時調用。
頁面中可以在打開頁面時直接調用js或者webservice介面。和定時調用action原理一樣
⑥ webview 遠程js調用本地java實現交互怎麼做
可以,只要你是用webview打開的,那麼不管事遠程還是本地,都可以通過webview與app的本地java代碼進行交互。沒有任何區別。
1、webview必須設置支持Javascript
mWebview.getSettings().setJavaScriptEnabled(true);
2、加進一個回調的代理類JavaScriptInterface,並給它一個調用的名稱:ncp
mWebView.addJavascriptInterface(newJavaScriptInterface(),"ncp");
finalclassJavaScriptInterface{
publicintcallOnJs(){
return1000;
}
publicvoidcallOnJs2(Stringmode){
//TODO
}
}
3、JS頁面
<scripttype="text/javascript">
window.onload=function(){
document.getElementById('btn_1').addEventListener('click',onBtnClick,false);
var_int_value=window.ncp.callOnJs();
alert("getintfromjava:"+_int_value);
}
functiononBtnClick(){
window.ncp.callOnJs2("click");
}
</script>
接下來就可以調用js方法了,
1、Java調用js方法
mWebView.loadUrl("javascript:onSaveCallback()");
2、JS訪問java方法
window.ncp.callOnJs2("click");
⑦ 如何在客戶端直接調用WebService中的方法
1.Web.config中需要配置好運行ASP.NET AJAX框架相應的配置項,當然,建立一個ASP.NET AJAX Enabled Web Site項目時,Web.config已經配置好了。
2.想讓某個WebService可以被JS調用,需要做一下幾步:
I.在這個WebService文件里用「using System.Web.Script.Services;」引入這個命名空間。
II.在這個類的上面添加「[ScriptService]」屬性。
III.在需要被調用的方法上添加「[WebMethod]」屬性。
具體例子可以參考《ASP.NET AJAX客戶端編程之旅(一)——Hello!ASP.NET AJAX》中的SayHelloService.cs的代碼。
3.調用WebService的客戶端頁面也要做相應准備。首先就是頁面中要有一個ScriptManager控制項,然後需要在其中指明WebService文件的位置。如:
<Services>
<asp:ServiceReference Path="~/SayHelloService.asmx" />
</Services>
將這段代碼放在<asp:ScriptManager>和<asp:ScriptManager />標簽之間,就可以使得這個頁面中的JS可以直接調用SayHelloService.asmx中的方法。具體代碼可以參考《ASP.NET AJAX客戶端編程之旅(一)——Hello!ASP.NET AJAX》中第二個例子中的Default.aspx的代碼。
做好以上三項准備,這個頁面中的JS代碼就可以使用我們熟悉的「類名.方法名」的方法直接調用WebService中的方法了。
⑧ js怎麼調用webserver
步驟1.在web.config中的system.web節點里加入
<!--此節點可允許腳本跨域調用webservice-->
<webServices>
<protocols>
<addname="HttpPost"/>
<addname="HttpGet"/>
</protocols>
</webServices>
<!--此節點可允許腳本跨域調用webservice-->
步驟2.webservice代碼
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Services;
usingSystem.Web.Mvc;
namespaceWebService
{
///<summary>
///WebService1的摘要說明
///</summary>
[WebService(Namespace="http://tempuri.org/")]
[WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
//若要允許使用ASP.NETAJAX從腳本中調用此Web服務,請取消對下行的注釋。
[System.Web.Script.Services.ScriptService]
publicclassWebService1:System.Web.Services.WebService
{
[ValidateInput(false)]
[WebMethod(Description="測試")]
publicvoidgetDBTableInfos(stringEnterpriseCode)
{
HttpContext.Current.Response.ContentType="application/json;charset=utf-8";
stringjsonCallBackFunName=string.Empty;
jsonCallBackFunName=HttpContext.Current.Request.Params["jsoncallback"].ToString();
HttpContext.Current.Response.Write(jsonCallBackFunName+"({"Result":""+EnterpriseCode+""})");
}
}
}
步驟3.html頁面部分
<!DOCTYPEhtml>
<html>
<head>
<title>Index</title>
<scriptsrc="http://www.cnblogs.com/Scripts/jquery-1.5.1.js"type="text/javascript"></script>
<scripttype="text/javascript">
$(function(){
$("#btnSubmit").click(function(){
varEnterpriseCode="39";
vardataStr="EnterpriseCode="+EnterpriseCode;
$.ajax({
type:"get",
url:"http://xxx/xxx.asmx/getDBTableInfos?jsoncallback?",
dataType:"jsonp",
jsonp:'jsoncallback',
data:dataStr,
success:function(result){
//返回結果
alert(result.Result);
}
});
});
});
</script>
</head>
<body>
<div>
<inputid="btnSubmit"type="button"value="查詢"/>
</div>
</body>
</html>
⑨ C# web頁面 調用本地的mstsc.exe(遠程桌面)
不能。如果網頁能隨便開你機器上的exe,你還敢上網嗎
⑩ 請問怎麼使用js或jquery的ajax跨域調用webservice,就是webservice已經部署在iis上了。。。
後台文件請求webservice 然後JS再請求本域的後台頁面。