Javascript 使用Ajax调用外部restapi
我是angular的新手,我正在尝试调用RESTAPI并获取其响应。我的问题是,我的JavaScript一直被Ajax调用卡住。我不确定是我发送的数据还是Ajax调用的语法。我试着提醒“Hello world”,这很有效,然后我提醒了JSON数组,该数组的格式正确,但是当我发布Ajax帖子时,我根本没有得到任何响应 任何见解都很好,谢谢 test.htmlJavascript 使用Ajax调用外部restapi,javascript,ajax,post,Javascript,Ajax,Post,我是angular的新手,我正在尝试调用RESTAPI并获取其响应。我的问题是,我的JavaScript一直被Ajax调用卡住。我不确定是我发送的数据还是Ajax调用的语法。我试着提醒“Hello world”,这很有效,然后我提醒了JSON数组,该数组的格式正确,但是当我发布Ajax帖子时,我根本没有得到任何响应 任何见解都很好,谢谢 test.html <button onclick="myFunction()">Post it</button> 你的问题与我无关。
<button onclick="myFunction()">Post it</button>
你的问题与我无关。我将向您介绍如何执行POST请求的angular docs描述,以及从docs中获取的语法的一个小示例 如果您想使用angular进行开发,请学习使用$http或类似的工具$http 小例子:
// Simple POST request example (passing data) :
$http.post('/someUrl', {msg:'hello word!'}).
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
您指定了一个相对URL,我认为您打算在其中指定一个绝对URL。如果当前页面URL为
http://localhost/myapp/
,您请求192.168.2.164/isapi/rip.dll/rest/session
,该URL解析为http://localhost/myapp/192.168.2.164/isapi/rip.dll/rest/session
如果192.168.2.164
是您试图访问的服务器的ip地址(而不是相对于服务器上当前路径的目录),则需要将/
添加到URL的开头以使其成为绝对的(至少是相对于架构的):
停止使用应用程序并开始阅读一些文档。。。您的示例与angularjs无关。您是否使用angularjs,然后使用serviceDefine“卡住”。成功的功用是什么?错误函数是否启动?在开发者工具控制台中看到消息了吗?您是否在“开发人员工具网络”选项卡中看到该请求?你看到那里的反应了吗?这两种格式都和你期望的一样吗?这和角种子有什么关系?对不起,伙计,我把我的问题说得更具体了。
// Simple POST request example (passing data) :
$http.post('/someUrl', {msg:'hello word!'}).
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
$.ajax({
url: '//192.168.2.164/isapi/rip.dll/rest/session',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify( postData ),
success: function(){
alert('hello');
},
error: function(){
alert('error');
}
});