I'm working on a script that's supposed to go over a table (see below) of users, complete with user IDs, and make a bunch of API requests which will update an online client database with arbitrary metadata about those users.
Here's the table:
<table id="msisdns_to_process">
<tr class="header">
<th>phone</th>
<th>First</th>
<th>Last</th>
<th>Favorite Book</th>
</tr>
<tr subid="4e8d1d81e89f75ffc1fd71b1">
<td class="unprocessed" mdid="4eb838400cf2384c4bd32ba5">18005882300</td>
<td class="unprocessed" mdid="4eb838400cf2384b3ac22ba5">Quentin</td>
<td class="unprocessed" mdid="4eb838480cf2384b3ac22ba6">Tarantino</td>
<td class="unprocessed" mdid="4ef3c054696e84d9342c46c1">Naked Lunch</td>
</tr>
<tr subid="4e8d92560cf24f1d7e67de28">
<td class="unprocessed" mdid="4eb838400cf2384c4bd32ba5">18005882300</td>
<td class="unprocessed" mdid="4eb838400cf2384b3ac22ba5">Wes</td>
<td class="unprocessed" mdid="4eb838480cf2384b3ac22ba6">Anderson</td>
<td class="unprocessed" mdid="4ef3c054696e84d9342c46c1">The Ticket That Exploded</td>
</tr>
<tr subid="4e8eacac2d6afa11cbdece8a">
<td class="unprocessed" mdid="4eb838400cf2384c4bd32ba5">18005882300</td>
<td class="unprocessed" mdid="4eb838400cf2384b3ac22ba5">David</td>
<td class="unprocessed" mdid="4eb838480cf2384b3ac22ba6">Cronenberg</td>
<td class="unprocessed" mdid="4ef3c054696e84d9342c46c1">Junky</td>
</tr>
</table>
So what I need to do is have a button press that will iterate over all of the non-header cells, making an API call that uses then subid attribute of the row, the mdid attribute of the cell and the value of the cell. Something like:
http://api.foo.bar/update/[subid]
POST payload: {"id":"[mdid]","value":"[cell text]"}
I'm fairly new to jQuery, so I'm probably getting tripped up on using the right selector, but here's what I have:
$("button#process_md").click(function(){
$("table#msisdns_to_process tr").each(function(){
var subid = this.attr("subid");
$("td.unprocessed").each(function(){
var mdid = this.attr("mdid");
var cont = this.contents();
$.ajax("/update"+subid,
{
data: { 'id': mdid,
'value':cont
},
headers: {'Accept': 'application/json'},
type: 'POST',
statusCode: {
200: function() {
$(this).addClass("processed");
$(this).removeClass("unprocessed");
}
}
}
});
});
...but I'm getting no result. I think, again, I'm doing the selection or iteration wrong. Any thoughts?