Updated Question:
$(this).attr("EmployeeId", 'A42345');
$.ajax({
type: "POST",
url: url,
data: "{EmployeeId: '" + id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var obj = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
var o = obj[$(this).attr("EmployeeId")]; //<<<<undefined
END UPDATE
i am trying to get EmployeeId withitn the DOM something like this:
var o = obj[$(this).attr("EmployeeId")];
but getting undefined
when i debug i see the following:
$(this)[0].data
data "{EmployeeId: 'A42345'}"
here is my source code:
$.ajax({
type: "POST",
url: url,
data: "{EmployeeId: '" + id + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var obj = (typeof response.d) == 'string' ? eval('(' + response.d + ')') : response.d;
var o = obj[$(this).attr("EmployeeId")]; //<<<<undefined
thisis referring to your function in the example you gave. Therefore your selector isn’t matching anything.I’m guessing you are calling an ajax function from within a click handler or some other type of event handler.
Assign $(this) to a variable in the first function and reference that variable in your success callback.
Posting more of your code would help though..
You may also be trying to access the data you were passing in.. in which case, parse it to json, or don’t pass it in as a string in the first place.. .attr won’t work on
$(this)though, asthisis referring to the function..$(this)[0].datais the function’s data. Which doesn’t have attributes, it’s not a DOM element.You are using some mismatched functionality, it’s hard for me to figure out exactly what your intent was.. You said you are trying to get it from the DOM, but you are showing the data of the function, those are two entirely different things.