jmgimeno (68) [Avatar] Offline
#1
In the javascript of listing 1.4 you use jquery but you don't use its facilities to make ajax requests, so you engage in low level details to get the XMLHttprequest object and you manage the status of the transaction. Jquery has facilities to simplify that, and the code can be much to the point that you want to show.

Juan Manuel
david.wood (45) [Avatar] Offline
#2
Re: Simplify listing 1.4
Thanks, Juan. I'll look into that...

Regards,
Dave
lucas.ruth (10) [Avatar] Offline
#3
Re: Simplify listing 1.4
Juan,

How does this look compared to the old code?

$("#turtle").click(function(event) {
event.preventDefault();
var request = $.ajax({
url: '?describe',
headers: { Accept : "text/turtle" }
});

request.done(function() {
var win = window.open('', document.URL);
win.document.write('<pre>
' + request.responseText.replace(/</g, '<').replace(/>/g, '>') + '
</pre>');
});

request.fail(function() {
alert("We're sorry, the request could not be completed at this time. Please try again shortly.");
});
});
jmgimeno (68) [Avatar] Offline
#4
Re: Simplify listing 1.4
Much clearer and easier to explain

Juan Manuel
lucas.ruth (10) [Avatar] Offline
#5
Re: Simplify listing 1.4
I agree! Glad to hear you do as well. Thanks for taking the time to point this out and help improve the book!
jmgimeno (68) [Avatar] Offline
#6
Re: Simplify listing 1.4
I'me reading MEAPv6 and now 90% of the code of the listing is the same (the unique difference is in the Accept header.

Maybe a litttle refakltoring will further simplify the code.

Juan Manuel
lucas.ruth (10) [Avatar] Offline
#7
Re: Simplify listing 1.4
Juan, that is a very good point. I will talk to my co-authors and look into refactoring it to accept a parameter and deal with it conditionally rather than duplicating the code like that. However, sometimes the most efficient code is not the easiest to read so we will weigh the pros and cons and get back to you.

As always, thanks for the feedback!