-4

Hello evry body i need a small help from your side explaning in bit detail about the below code which i couldnt able to understand as i was bit new to the this Jquery...

hope i can get a proper response from your side and explanation from scratch about the functionality from the level of wrapper classes which is embedded in this jquery function BindProfileDetails() {

$.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "NewMyprofile.aspx/Populate_details",
                dataType: "json",
                success: function (data) {
                    if (data.d) {
                        $(data.d).each(function (index, item) {

                            if (index == 0) {

                                $("#txtfname").val(item.fname);
                                $('#txtLname ').val(item.lname);
                                $('#Txtsurname').val(item.surname);
                                $('#txtmob').val(item.mob);
                                $('#Txtphone').val(item.phone);
                                $('#Txtextension').val(item.ext);
                                $('#ddlyop').val(item.yop);
                                $('#txtEmailId').val(item.email);
                                $('#txtaddress ').val(item.address);
                                $('#txtadd1').val(item.addrclg);
                                $('#txtqual').val(item.quali);
                                $('#Txtuniv').val(item.univ);

                                if (item.sex == "True") {
                                    $("#rdbmale").attr("checked", false);
                                    $("#rdfemale").attr("checked", true);
                                }
                                else {
                                    $("#rdbmale").attr("checked", true);
                                    $("#rdfemale").attr("checked", false);
                                }

                                if (item.maritialst == "True") {
                                    $("#rdmarry").attr("checked", false);
                                    $("#Rdsingle").attr("checked", true);
                                }
                                else {
                                    $("#rdmarry").attr("checked", true);
                                    $("#Rdsingle").attr("checked", false);
                                }

                            }
                        });
                    }

                }

            });

        }
clarifier
  • 119
  • 1
  • 13

1 Answers1

2

Let me try to explain -

  1. 'ajax' stands for Async. Javascript And XML. You can make XML HTTP Requests using ajax.

  2. type - Describes the type of your request (POST/GET/PUT/DELETE) - you need to specify your request type in this section. Know more on the request types here.

  3. url - defines the url to which you want to make the request.

  4. dataType and contentType - preferred data type and content type for the communication.

  5. success - program control will come into it if the communication succeeds. You can have the response as the function parameter (For your case, this is 'data').

  6. data.d - The response is wrapped with a key 'd'. So, you will get the actual response in 'data.d', not in data. This is customizable. Know more here.

  7. $(data.d).each(function (index, item) - Does a simple 'foreach' loop with your data.d object. So, it will execute for each item present in your data.d object. The parameters - 'item' holds the actual item (current item) and 'index' holds the loop-index. As per your code, this is setting values to some fields using the data item.

Hope this helps you.

Community
  • 1
  • 1
Subha
  • 1,051
  • 1
  • 6
  • 12