Reputation: 77
jquery $.post:
$.post(
'includes/studiesAjax/addTryb.php',
{inputVL: inputVL},
function(res){
$("#container").html(res);
}
);
response is long html code
I would like to extract data from the first line of response beetween <p>
tag, separate it from response and assign to new variable. How to do it?
Upvotes: 0
Views: 132
Reputation: 9968
If you return json instead html you can do like this.
$.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);
}
);
Upvotes: 0
Reputation: 17930
You should transform the response to a jquery object and then you can act on as usual:
$.post(
'includes/studiesAjax/addTryb.php',
{inputVL: inputVL},
function(res){
var result = $(res).find('p:first').html();
$("#container").html(result );
}
);
Upvotes: 0
Reputation: 60516
function(res){
var newVar = $(res).find('p:first').html();
}
Upvotes: 3