I am using JQuery to post with AJAX to another ASP page. Do I need this ASP page to return a full html page. Or can I just have it send back a value ( I just need a status ) . Here is my function.
我正在使用JQuery将AJAX发布到另一个ASP页面。我是否需要此ASP页面才能返回完整的html页面。或者我可以让它发回一个值(我只需要一个状态)。这是我的功能。
$.ajax({
url: "X.asp",
cache: false,
type: "POST",
data: queryString,
success: function(html){
$('#x_'+Num).append(html);
}
});
5 个解决方案
#1
14
If it's just a simple value you need, I'd simple use Json (JQuery has a dedicated method for that : $.getJSON()).
如果它只是一个你需要的简单值,我会简单地使用Json(JQuery有一个专门的方法:$ .getJSON())。
So no, you don't need your ASP page to return a full html page, just the value in simple JSON notation.
所以不,你不需要你的ASP页面返回一个完整的html页面,只需要简单的JSON表示法中的值。
#2
1
You can return anything you want (even single character), but remember to change content type of your page X.asp to ContentType="text/plain" if you don't want to return HTML.
您可以返回任何您想要的内容(甚至是单个字符),但如果您不想返回HTML,请记住将页面的内容类型X.asp更改为ContentType =“text / plain”。
#3
1
Well, the whole point of AJAX is IMHO that you don't need to return the whole page. The server just sends the simple answer that you need.
好吧,AJAX的重点是恕我直言,你不需要返回整个页面。服务器只发送您需要的简单答案。
#4
1
You can return anything from the backend, I personally prefer JSON, but you have to specify the dataType property in your $.ajax options
您可以从后端返回任何内容,我个人更喜欢JSON,但您必须在$ .ajax选项中指定dataType属性
#5
0
Using AJAX, you can return anything, even binary data. Although it was designed for XML, you can use it for anything you can transfer across a web server. However, HTTP Requests are expensive, so don't abuse them too much!
使用AJAX,您可以返回任何内容,甚至是二进制数据。虽然它是为XML设计的,但您可以将它用于可以通过Web服务器传输的任何内容。但是,HTTP请求很昂贵,所以不要滥用太多!
#1
14
If it's just a simple value you need, I'd simple use Json (JQuery has a dedicated method for that : $.getJSON()).
如果它只是一个你需要的简单值,我会简单地使用Json(JQuery有一个专门的方法:$ .getJSON())。
So no, you don't need your ASP page to return a full html page, just the value in simple JSON notation.
所以不,你不需要你的ASP页面返回一个完整的html页面,只需要简单的JSON表示法中的值。
#2
1
You can return anything you want (even single character), but remember to change content type of your page X.asp to ContentType="text/plain" if you don't want to return HTML.
您可以返回任何您想要的内容(甚至是单个字符),但如果您不想返回HTML,请记住将页面的内容类型X.asp更改为ContentType =“text / plain”。
#3
1
Well, the whole point of AJAX is IMHO that you don't need to return the whole page. The server just sends the simple answer that you need.
好吧,AJAX的重点是恕我直言,你不需要返回整个页面。服务器只发送您需要的简单答案。
#4
1
You can return anything from the backend, I personally prefer JSON, but you have to specify the dataType property in your $.ajax options
您可以从后端返回任何内容,我个人更喜欢JSON,但您必须在$ .ajax选项中指定dataType属性
#5
0
Using AJAX, you can return anything, even binary data. Although it was designed for XML, you can use it for anything you can transfer across a web server. However, HTTP Requests are expensive, so don't abuse them too much!
使用AJAX,您可以返回任何内容,甚至是二进制数据。虽然它是为XML设计的,但您可以将它用于可以通过Web服务器传输的任何内容。但是,HTTP请求很昂贵,所以不要滥用太多!