$.ajax({ type : "post", url : "ws/customs/myService?reqXml=abcd", success : function(msg){ console.log("------"); console.log(msg); }, error : function(msg) { console.log("-----" + msg); }, });为什么这样可以调用服务呢
时间: 2024-02-15 17:27:40 浏览: 26
这因为该代码使用了 jQuery 的 AJAX 方法,可以向指定的 URL 发送 HTTP 请求,并在请求成功或失败时执行指定的回调函数。在这个例子中,请求的类型为 POST,URL 是 "ws/customs/myService",请求参数是 "reqXml=abcd"。当请求成功时,会执行 success 回调函数并打印返回的数据,当请求失败时,会执行 error 回调函数并打印错误信息。因此,该代码可以调用指定 URL 上的服务并获取服务返回的数据。
相关问题
Caused by: com.android.tools.r8.utils.AbortException: Error: Invoke-customs are only supported starting with Android O (--min-api 26)
这个错误是因为您的 Android 项目的最小 API 版本低于 26,而 invoke-custom 指令只支持在 Android O 或更高版本上使用。要解决这个问题,您需要将最小 API 版本升级到 26 或更高版本。具体的做法是在您的 app 模块的 build.gradle 文件中将 minSdkVersion 设置为 26,如下所示:
```
android {
defaultConfig {
minSdkVersion 26
// other configurations
}
// other configurations
}
```
请注意,将最小 API 版本设置为 26 可能会导致您的应用无法在低于 Android O 的设备上运行。因此,在升级之前请务必进行测试,并根据您的应用的受众和需求进行权衡。
但是service的服务确实post
如果你的服务确实是 POST 请求,那么你需要将这个 $.ajax() 方法中的 "type" 属性值修改为 "post",以便将请求类型设置为 POST。此外,你需要将请求参数从 URL 中删除,改为通过 "data" 属性传递。例如,代码可以修改为以下形式:
```
$.ajax({
type: "post",
url: "ws/customs/myService",
data: { reqXml: "abcd" },
success: function(msg){
console.log("------");
console.log(msg);
},
error: function(msg) {
console.log("-----" + msg);
},
});
```
在这个例子中,请求类型被设置为 POST,请求参数被封装在 "data" 属性中。这样,请求将会以 POST 方式发送到指定的 URL,并且请求参数将会被放置在请求体中。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)