AJAX - Do I need to return a full HTML document on the server side?

I am using jQuery to publish with AJAX on another ASP page. I need this ASP page to return the full html page. Or I can just send it back (I just need a status). Here is my function.

    $.ajax({
      url: "X.asp",
      cache: false,
      type:  "POST",
      data:  queryString,
      success: function(html){
        $('#x_'+Num).append(html);
      }
    });
+3
source share
5 answers

If this is just the required value, I would just use Json (JQuery has a dedicated method for this: $. GetJSON () ).

No, you don't need your ASP page to return a full html page, just a value in simple JSON notation.

+14
source

, ( ), X.asp ContentType = "text/plain", HTML.

+1

Well, in general, the goal of AJAX is IMHO that you do not need to return the entire page. The server just sends the simple answer you need.

+1
source

You can return something from the backend, I personally prefer JSON, but you must specify the dataType property in the $ .ajax parameters

+1
source

Using AJAX, you can return anything, even binary data. Although it was designed for XML, you can use it for everything that you can pass through a web server. However, HTTP requests are expensive, so don't abuse them too much!

0
source

Source: https://habr.com/ru/post/1699077/


All Articles