如何在Ajax中获取HTML响应获取请求?

时间:2017-03-20 14:52:29

标签: javascript

$.ajax({
        type: "GET",
        url: url,
        dataType: 'html',
        async: false,
        crossDomain: true,
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'GET, POST,PUT',
            'Content-Type': 'text/html'
        },
        success: function (data) {
            debugger;
            console.log($(data));
        },
        error: function (xhr, ajaxOptions, thrownError) {
            debugger;
            console.log('xHR: ' + xhr);
            console.log('ajaxOption: ' + ajaxOptions);
            console.log('thrownError: ' + thrownError);
        }
    });

1 个答案:

答案 0 :(得分:0)

您可以使用此脚本获取HTML响应。



$().ready(function () {
        $.ajax({
            type: "GET",
            url: 'http://vindhyatest.comule.com/content.php',
            crossDomain: true,
            success: function (data) {
                $('#content').html(data);
            },
            error: function (xhr, ajaxOptions, thrownError) {
                console.log('xHR: ' + xhr);
                console.log('ajaxOption: ' + ajaxOptions);
                console.log('thrownError: ' + thrownError);
            }
           });
         });

	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.2/jquery.min.js"></script>
	<div id="content"></div>
&#13;
&#13;
&#13;