如何在javascript和javascript之间实现ajax
我需要对javascript执行ajax,并通过调用js函数获得结果。 但我无法获取数据 我正在制作TizenWeb应用程序。 我的服务器上有web服务(asp)。 我在我的网站上使用了ajax,但出现了错误。 如您所见,我试图通过console.log进行调试,但没有打印任何合理的值 app.js(90):getAlarmData() app.js(153): app.js(90):getAlarmData() app.js(153):如何在javascript和javascript之间实现ajax,javascript,jquery,ajax,Javascript,Jquery,Ajax,我需要对javascript执行ajax,并通过调用js函数获得结果。 但我无法获取数据 我正在制作TizenWeb应用程序。 我的服务器上有web服务(asp)。 我在我的网站上使用了ajax,但出现了错误。 如您所见,我试图通过console.log进行调试,但没有打印任何合理的值 app.js(90):getAlarmData() app.js(153): app.js(90):getAlarmData() app.js(153): 您试图对服务器上存在的文件执行函数调用,但不能直接执行。
您试图对服务器上存在的文件执行函数调用,但不能直接执行。您必须在服务器上打开一条道路,返回您的功能结果 您必须了解如何使用单页应用程序(SPA-前端应用程序)和API(服务器端应用程序)进行通信 例如:
$.ajax({
type: "POST"
, url: "serverIP/my/awesome/road/which/calling/my/function"
, data: null
, contentType: "application/json; charset=utf-8"
, dataType: "json"
, async: false
, success: function (jSonResult) {
console.log( jSonResult );
},
error: function (xhr, status, error) {
console.log(error + "\n" + status + "\n" + xhr.responseText);
}
});
对于简历,您必须:
- 在服务器上打开一条道路
- 在调用中返回函数的结果(jSonResult)
- 在成功回调中使用它
$.ajax({
type: "POST"
, url: "serverIP/my/awesome/road/which/calling/my/function"
, data: null
, contentType: "application/json; charset=utf-8"
, dataType: "json"
, async: false
, success: function (jSonResult) {
console.log( jSonResult );
},
error: function (xhr, status, error) {
console.log(error + "\n" + status + "\n" + xhr.responseText);
}
});