jQuery $.post:
$.post(
    'includes/studiesAjax/addTryb.php',
    {inputVL: inputVL},
    function(res){
        $("#container").html(res);
    }
);
响应是长 html 代码
我想从响应 beetween<p>标签的第一行中提取数据,将其与响应分开并分配给新变量。怎么做?
function(res){
    var newVar = $(res).find('p:first').html();
}
您应该将响应转换为 jquery 对象,然后您可以照常操作:
$.post(
            'includes/studiesAjax/addTryb.php',
            {inputVL: inputVL},
            function(res){
                var result = $(res).find('p:first').html();
                $("#container").html(result );
            }
        );
如果你返回 json 而不是 html 你可以这样做。
       $.post(
            'includes/studiesAjax/addTryb.php',
            {inputVL: inputVL},
            function(res){
                var data = JSON.parse(res);
                if(data && data.response1){
                    result = (data.response1);
                    console.log(result);
                }
                if(data && data.response2)
                    $("#container").html(data.response2);
            }
        );