當前位置:首頁 » 網頁前端 » 前端調用介面
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

前端調用介面

發布時間: 2022-03-08 17:51:45

前端調用後端介面demo

樓主,可以去後盾人找一下問題,那些教學視頻都是高清,你這個問題應該講解過.

❷ 前端調用介面404報錯

今天遇到了一個很離奇的場景,使用ajax請求後台結果 後台處理成功了頁面還報了404錯誤。
程序員不說話,默默上代碼:
JS:
[javascript] view plain
var save = function(){
$.ajax({
url: urlMap.saveOrUpdateGroupInfo,
type: 'post',
async: false,
dataType: 'json',
data: $("#groupInfo").serialize()
}).done(function(res) {
console.log(res);
if(res.success) {

}else{
bootbox.alert(res.msg);

}
});
}
後端:
[java] view plain
@RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
public ResponseVo saveOrUpdate(String id, String name, String parentId, String parentName, String operate){
ResponseVo result = new ResponseVo();
GroupInfo info = new GroupInfo();
Date now =new Date();
info.setUpdateTime(now);
try{
if(operate.equals("add")){
info.setParentId(Integer.parseInt(parentId));
info.setName(name);
info.setCreateTime(now);
groupInfoService.addGroup(info);
}else if (operate.equals("edit")) {
info.setId(Integer.parseInt(id));
info.setName(name);
info.setParentId(Integer.parseInt(parentId));
groupInfoService.updateGroup(info);
}else if (operate.equals("delete")) {
groupInfoService.deleteGroup(Integer.parseInt(id));
}
result.setSuccess(true);
}catch (Exception e){
log.error("operate group error."+ JsonUtil.toString(info), e);
result.setSuccess(false);
result.setMsg(e.getMessage());
}
return result;
}
}
挺奇怪吧?
經分析是請求沒有返回狀態碼,這是因為我用的是SpringMVC框架,前後端使用JSON傳遞數據,因為返回的是對象,而忘記了添加
@ResponseBody
註解,所以 Spring對我的返回值進行了映射,但是映射結果又對應不到視圖,所以返回了404
正常後台代碼:
[java] view plain
@RequestMapping(value = "/saveOrUpdate", method = RequestMethod.POST)
@ResponseBody
public ResponseVo saveOrUpdate(String id, String name, String parentId, String parentName, String operate){
ResponseVo result = new ResponseVo();
GroupInfo info = new GroupInfo();
Date now =new Date();
info.setUpdateTime(now);
try{
if(operate.equals("add")){
info.setParentId(Integer.parseInt(parentId));
info.setName(name);
info.setCreateTime(now);
groupInfoService.addGroup(info);
}else if (operate.equals("edit")) {
info.setId(Integer.parseInt(id));
info.setName(name);
info.setParentId(Integer.parseInt(parentId));
groupInfoService.updateGroup(info);
}else if (operate.equals("delete")) {
groupInfoService.deleteGroup(Integer.parseInt(id));
}
result.setSuccess(true);
}catch (Exception e){
log.error("operate group error."+ JsonUtil.toString(info), e);
result.setSuccess(false);
result.setMsg(e.getMessage());
}
return result;
}

❸ 前端怎麼調用後台介面

用ajax發送請求到後台 後台接受數據 然後處理邏輯 最後成功了 返回給前端啊

❹ 前端可以用調用後端提供的介面嗎

您好:
要看後端的介面類型和介面協議。
有些是可以通過jquery進行提交的。
具體請與後端開發進行溝通。

❺ web前端ajax怎麼調用介面

$.ajax({
type: "post/get",
url: "地址",
data: {
key: value
},
dataType: "json",
async: false/yrue,
success: function(e) {
alert(e);

}

❻ 前端調用後端介面介面什麼意思

介面指可以通過服務端部署的機器提供出來的URL地址進行動態的數據交互,通常的工作流是後端跟前端協商定義數據介面格式形成文檔,後端實現介面,前端做靜態的mock,後端實現服務介面,兩邊都完成後集成聯調,現在有swagger或者 apiairy等工具可以更簡化這個過程。

❼ JS怎麼調用API介面

需要准備的材料分別是:電腦、html編輯器、瀏覽器。

1、首先,打開html編輯器,新建html文件,例如:index.html,引入jquery使用。

❽ 前端怎麼調用api介面

方法/步驟

  • 先定義一個簡單的webapi,簡單到差不多直接用vs2010自動生成的webapi代碼。

    其中的TestModle是一個簡單的class,如下

    public class TestModle

    {

    public string a { get; set; }

    public string b { get; set; }

    public string c { get; set; }

    }

❾ web前端怎麼調用api介面

1、首先需要確定第三方的介面的基本信息:地址、請求方式,參數、返回值,介面模式這里第三方的介面是restful風格的,採用get請求。