为什么阿贾克斯get请求失败 [英] why Ajax get Request failed
问题描述
我的请求的响应是一个Java Script code。当我把网址浏览器,我可以看到在页面上生成的整个Java脚本code。 URL传递到$就的格式如下:
The response of my request is a java script code. When I put the url in browser, I can see the whole generated java script code on the page. Format of url passed to $.ajax is as below:
http://localhost:8080/vi-api/viapi?action=tag&projectId=45&tagId=345
当我把上面的网址,我可以看到该请求是成功的。现在,我使用下面的Ajax请求使用jQuery这个网址。
When I put the above URL I can see the request is successful. Now, I am using below Ajax request for this url using jQuery.
var finalUrl = "http://localhost:8080/vi-api/viapi?action=tag&projectId=45&tagId=345";
var req = $.ajax({
type:"GET",
url:finalUrl,
type:"script",
data:"",
success: function(html){
alert('Requese sucessful.');
},
complete:function(jqXHR, textStatus) {
alert("request complete "+textStatus);
},
error: function(xhr, textStatus, errorThrown){
alert('request failed->'+textStatus);
}
});
问题1:给出警告请求失败,错误'为什么会是这样
Question 1:This gives the alert "request failed error'. Why this is so ?
问题2:有没有办法返回成功/失败code在上面的过程
Question 2:Is there any way to return success/failure code in above process?
推荐答案
在
$.ajax({
type:"GET",
url:finalUrl,
type:"script",
(...)
您的对象两次的类型键。因此,我认为只有第二个取(脚本)。显然,脚本不是一个有效的HTTP方法(如HEAD,GET,PUT,POST等)。你在看的脚本的关键词是可能的dataType
这可能是 XML
,<$ C $之一C> JSON , JSONP
,文本
,剧本
或 HTML
。
You have two times the 'type' key in your object. So I think only the second one is taken ('script'). Obviously 'script' is not a valid HTTP method (as HEAD,GET,PUT,POST, etc). The keyword your were looking at for 'script' is maybe dataType
which may be one of xml
, json
, jsonp
, text
, script
, or html
.
不要忘了看看 JSONP
,它通常是一个不错的方法,返回一个脚本内容,并调用它。
Do not forget to look at jsonp
, it's usually a nice way to return a script content and to call it.
这篇关于为什么阿贾克斯get请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!