0

I have simple update call where I make a ajax Jason request to get the data but the Jason request is appending this d:null at the end.

Here is my ajax call

 $('#datatable').on("click", ".editButton", function () {
                $('#myModal').focus();
                var id = $(this).data('id');               
                $.ajax
                    ({                        
                        type: "post",
                        contentType: "application/json;charset=utf-8",
                        url: 'GetECWResourceInfo_Json.asmx/GetbyID',
                        data: '{id: ' + id + '}',                 
                        dataType: "json",
                        success: function (data)
                        {
                            var tbDetails = $.parseJSON(data.d);
                            $.each(tbDetails, function (index, value)
                            {
                                                                $("#txtECWResource").val(value.ECWResource);
                                $("#txtVisionResource").val(value.VisionResource);
                                $("#txtECWResourceLName").val(value.ECWResourceLName);
                                $("#txtECWResourceFName").val(value.ECWResourceFName);
                                $("#txtECWProvider").val(value.ECWProvider);
                                $("#txtVisionLocation").val(value.VisionLocation);
                                $("#txtECWProviderLastName").val(value.ECWProviderLastName);
                                $("#txtECWProviderFirstName").val(value.ECWProviderFirstName);
                                $("#txtLocationSpecific").val(value.LocationSpecific);
                                $("#txtUID").val(value.UID);
                            });
                        },
                        error: function (err) {
                            alert(err.responseJSON.error);
                        }
                    });
            });

My Method in asmx to get the Json data

public void  GetbyID(int id ) 
            {           
                string cs = ConfigurationManager.ConnectionStrings["con"].ConnectionString;
                //Return list
                List<ECW_resource_Info> lstbyID = new List<ECW_resource_Info>();
                using (SqlConnection con = new SqlConnection(cs))
                {
                    SqlCommand com = new SqlCommand("gp_GetResourceInfobyID", con);
                    com.CommandType = CommandType.StoredProcedure;
                    //com.Parameters.Add(new SqlParameter() { ParameterName = "@CmdType", Value = key });

                    com.Parameters.Add(new SqlParameter() { ParameterName = "@UID", Value = id });
                   // com.Parameters.Add(new SqlParameter() { Value = id });
                    con.Open();
                    SqlDataReader rdr = com.ExecuteReader();
                    while (rdr.Read())
                    {
                        lstbyID.Add(new ECW_resource_Info
                        {
                            ECWResource = rdr["ECWResource"].ToString(),
                            VisionResource = rdr["VisionResource"].ToString(),
                            ECWResourceLName = rdr["ECWResourceLName"].ToString(),
                            ECWResourceFName = rdr["ECWResourceFName"].ToString(),
                            ECWProvider = rdr["ECWProvider"].ToString(),
                            VisionLocation = rdr["VisionLocation"].ToString(),
                            ECWProviderLastName = rdr["ECWProviderLastName"].ToString(),
                            ECWProviderFirstName = rdr["ECWProviderFirstName"].ToString(),
                            LocationSpecific = rdr["ECWProviderFirstName"].ToString(),
                            UID = Convert.ToInt32(rdr["UID"])
                        });
                    }
                }

                JavaScriptSerializer js = new JavaScriptSerializer();
                //serialize it to a json object we write it to a parent response stream.            
                Context.Response.Write(js.Serialize(lstbyID));       
            }

When i evoke the GetbyID method by running the asmx page the result i get after passing the id key

[{"ECWResource":"a1 ","VisionResource":"a1 ","ECWResourceLName":"a1 ","ECWResourceFName":"a1 ","ECWProvider":"a1 ","VisionLocation":"a1 ","ECWProviderLastName":"a1 ","ECWProviderFirstName":"a1 ","LocationSpecific":"a1 ","UID":2102}]

When i press the same line number with the key to EDIT this is what it throws. Please look at the end as it appends this crazy d:null and adds crazy spaces. I am really having a crazy time here. Thank you for having a look. enter image description here

user3920526
  • 404
  • 4
  • 20
  • Try to change your error function into this. `error: function(xhr, status, error) { var err = JSON.parse(xhr.responseText); alert(err.Message); }` https://stackoverflow.com/questions/1637019/how-to-get-the-jquery-ajax-error-response-text – Jay Marvin Apr 27 '18 at 03:11
  • thank you for having a look. – user3920526 Apr 27 '18 at 12:57

0 Answers0