简体   繁体   中英

How to load html response on browser using ajax call

I am calling a vbscript page using post method from ajax call and in return we are getting html data from vbscript page. Is there any function exist in ajax which we can use to load that html response on browser, like we do Response.Write in vbscript. I googled for almost all possible solution, but didn't find anything relevant. Your little help will be highly appreciated.

Ajax Function : 
<script type="text/javascript">
        function ajaxcallforstatus() {
            $.ajax({ 
            type : "POST",
            url: "http://someURL",
            dataType : "application/json",
            data : $("#status1").val().trim(),
            statusCode:{
                    401:function (data) {
                    $("#status1").val(data.responseText);
                    },
                    400: function (data) {
                        $("#status1").val(data.responseText);
                    },
                    200:function (data) {
                        alert(data.responseText);
                    },
                    500:function (data) {
                    $("#status1").val(data.responseText);
                    }
                }
            }); 
        }
</script>

Note : When we are getting status 200, we want to load the html response(data.responseText) on the browser.

you may try .load in jquery

$(element).load('path of the file')

or maybe you need .html in jquery

$(element).html('html code here');

Add a success option to your AJAX call. Here's a code snippet that should help.

function ajaxcallforstatus() {
  $.ajax({ 
    type : "POST",
    url: "http://someURL",
    dataType : "application/json",
    data : $("#status1").val().trim(),
    statusCode:{
      401:function (data) {
        $("#status1").val(data.responseText);
      },
      400: function (data) {
        $("#status1").val(data.responseText);
      }, 
      //I removed the 200 status because
      //that's what the success callback is for.
      500:function (data) {
        $("#status1").val(data.responseText);
      }
    },
    success: function(response) { //<- When it returns successfully,
      $('#myDiv').html(response); 
      //^ Put the returned HTML into the HTML element with id="myDiv"
    }
  }); 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM