Get hidden field value that came with ajax call

How can I check using jQuery or javascript a hidden field value that just came in html with ajax call? There must be something easy but cannot find anything.

Related posts

Leave a Reply

1 comment

  1. If your ajax response is an HTML you can do this:

    var hiddenValue = $('yourHiddenSelector', $(ajaxResponseHtml)).val();
    

    for example if your ajax response is:

    '<div class="container"><input type="hidden" value="3" id="myhidden" name="number"></div>'
    

    Your code could be like this:

    $.ajax({
        url: url,
        type: 'POST',
        data: {},
        success: function(ajaxResponseHtml){
             var hiddenValue = $('#myhidden', $(ajaxResponseHtml)).val(); //output 3
        },
        error: function(){ alert('error');}
    });