Reputation: 21308
I have the following link:
<a href="/Packages/PackageActionDownloadAsync" data-ajax-type="Download" data-ajax-packageid="AGI-VS-GAME-M52-1.5.3.2.67" data-ajax-machineid="30" class="iconGear action tip" data-hasqtip="true" oldtitle="Download" title="" aria-describedby="qtip-1">Download</a>
and javascript code:
var obj = $(this),
objData = obj.data(),
packageId = objData.ajaxPackageid,
operation = objData.ajaxType;
I tried this:
alert(objData.ajaxPackageid);
alert(objData.ajaxPackageId);
alert(objData.AjaxPackageId);
they all return "undefined". The only one that works is this:
alert(objData.ajaxType);
what is going on? I'm using "jquery-1.7.1.js"
Upvotes: 2
Views: 3187
Reputation: 56429
I'm suprised any of them work accessing them like that. You need to access them via string names in jQuery. Like so:
var obj = $(this);
alert(obj.data("ajax-packageid"));
alert(obj.data("ajax-type"));
alert(obj.data("ajax-machineid"));
Take a look at the jquery .data
object
DEMO: http://jsfiddle.net/xFmn3/
Upvotes: 4
Reputation: 94429
You need to pass the key for the data you want to receive to the data()
function.
var obj = $(this),
packageId = obj.data("ajax-packageid"),
operation = obj.data("ajax-type");
Working Example: http://jsfiddle.net/sUSCe/
Upvotes: 2