Ainsley was born in Douglas, in the Isle of Man, an island in between Britain and Ireland. He was raised in a fishing community, and enlisted as a Midshipman in the Royal Navy at the age of 19. In 1770, he was stationed in Boston with HMS Connor, but later transferred to HMS Commerce, which was a medium-sized brig, and became the Captain in 1773. However, with the Revolutionary War starting, he accepted an invitation by the Continental Congress to become one of the first captains of the Continental Navy, captaining USS Maine.
Ainsley took part in the attack on Providence Harbor in April 1776 as a part of the Blockade of Providence by a British fleet led by David Greene, and managed to damage the British ships HMS Zebra (1769) and HMS Hector (1765), but his ship was routed after fierce naval combat in which his ship was damaged by enemy gunfire, but he destroyed the sails of the enemy warships. During his career, he also damaged HMS Zama off the coast of Virginia and sunk the HMS Stanley off of Shetley Island. The Battle of Shetley Island was his first notable victory, but it was followed up by further blockading of enemy trade routes overseas.
In December 1776, Ainsley and the USS Maine took part in an attack on the British fleet off of Baltimore, facing HMS Magnificent (1770) and Captain Carl Digby. The USS Maine attacked the ship, assisted by USS Voyager (captained by Abner Basset), but their port side was lined with holes from naval gunfire, and the ship was sunk. Ainsley refused to leave the cabin. When a subordiante officer, Midshipman Thomas Holey, told him, "Sir, the ship is sinking", he responded, "But it isn't even three o'clock yet!", referring to the time that lunch hour was supposed to be at. With a gulp of whiskey, he died, drowning as the sloop sunk into the Atlantic Ocean. The battle was a victory by the US, but as they failed to take down HMS Magnificent, the loss of Ainsley was a huge benefit for the British.