skip to Main Content
$.ajax({
            url: '/cash/bill/PostingBillTypeCombo',
            dataType: 'html',
            data: {
                name: "BillTypeId",
                required: true,
                currencyId: selectedCurrencyId
            },
            method: 'POST',
            success: function (data) {
                ------
                -----
                
                }

            },
        });

enter image description here

how can i capture data inside function (data) the above image is the data which is send to function (data).

i need to capture the Debit inside the function(data).

Should i stringfy and capture it or is there another way of doing it?

Should i capture it using option value or is there another way of doing it?

Im a beginner so help me out on this.This is for my school project

2

Answers


  1. You can store the value to a variable then transfer using ajax. You need to stringify only if it’s an array or object.

    var option_value = $("#BillTypeId option:selected"); 
    $.ajax({
                url: '/cash/bill/PostingBillTypeCombo',
                data: {result: option_value},
                method: 'POST',
                success: function (data) {
                    ------
                    -----
                    
                    }
    
                },
         });
    

    In server side if you are using php you can get the value by using this method

    $option_value = $_POST[‘result’];

    Login or Signup to reply.
  2. Considering you are using it with jQuery, I have created a Sample for you.

    As you are getting your as a string in data, you can create a dummy template and access the element with CSS selector.

    Try with below code:

    var txt="<select><option value ='1000'>DEBIT</option><option value ='9999'> Credit</option></select>";
    var parser = new DOMParser();
    var htmlDoc = parser.parseFromString(txt, 'text/html');
     
    
    $(htmlDoc).find('option:contains("DEBIT")').val()
    

    //OutPut:"1000"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search