Wal-Mart on Thursday reported second-quarter earnings and sales that topped Street expectations, as the big-box retailer made further gains in its online business.

Fresh digital initiatives and a growing assortment of products on Walmart.com aided the retailer in boosting online transactions by 60 percent, the company said. Last quarter, e-commerce sales climbed 63 percent, compared with 29 percent growth in the prior quarter.

Although many retailers are struggling to draw shoppers in, Wal-Mart posted same-store sales growth at its U.S. locations for the 12th-consecutive quarter, fueled by traffic growth of 1.3 percent, the company said.

Despite the news, shares of Wal-Mart were down more than 2.5 percent during premarket trading.

Here's what Wal-Mart reported compared to what Wall Street was expecting, based on a Thomson Reuters survey of analysts:

Earnings of $1.08 a share, adjusted, compared with a forecast profit of $1.07 per share.

Revenue was $123.36 billion versus an estimate of $122.84 billion.

Same-store sales for U.S. stores, excluding fuel, climbed 1.7 percent, matching expectations.

"This isn't a blow-away report ... it's a solid report," Gordon Haskett analyst Chuck Grom told CNBC's "Squawk Box." Wal-Mart's stock has been a "big outperformer" of late, Grom added, which can lead to a temporary sell-off, "even if the print is perfect."

"I think this number needed to be a little bit better today to drive the stock higher," he said.

One weakness for Wal-Mart the second quarter was that profit margins fell slightly due to more aggressive promotions. The retailer has been investing heavily to keep its prices competitive, defending market share from Amazon, among other rivals. It also bulking up its online operations. The expensive moves are yielding results.

"Our customers are responding to the improvements in stores and online, and our results reflect this," CEO Doug McMillon said in a statement. "Traffic increases at store level and the eCommerce growth rate are key highlights."

The Bentonville, Arkansas-based retailer said it earned 96 cents per share during the period. Excluding one-time charges, the company earned $1.08 a share.

Wal-Mart's total sales climbed 2.1 percent from a year ago, to $123.36 billion. This consisted of 3.3 percent sales growth at Wal-Mart U.S. stores, a 1 percent decline in revenues for Wal-Mart's international business and 2.3 percent growth across Sam's Club.

Wal-Mart's U.S. comparable sales — a metric closely watched by the Street for retailers — increased 1.8 percent, including fuel. Excluding gasoline sales, comps in the U.S. were up 1.7 percent, which consisted of growth of 1.2 percent at Sam's Club, and an increase of 1.8 percent at Wal-Mart stores.

"It was another solid quarter ... we are pleased with the first half of the year," CFO Brett Biggs told CNBC. "I think one of the things I'm most excited about is that we continued to bring together what we are doing in the stores with what we are doing online."

Looking ahead, Wal-Mart raised the low end of its earnings outlook for the full year, now forecasting profit ranging from $4.30 to $4.40 per share, adjusted. Previously, Wal-Mart had said it expected to earn $4.20 to $4.40 a share. A survey of analysts by Thomson Reuters was calling for earnings per share of $4.37.

Same-store sales, excluding fuel, are expected to climb 1.5 to 2 percent at Wal-Mart U.S. locations in the third quarter of 2017.

In a competitive retail environment, the big-box retailer has been defending its turf against internet giant Amazon, especially in the digital world. Wal-Mart is also reportedly expanding its online advertising business.

Some of Wal-Mart's latest efforts to get purchases more quickly and efficiently to customers include testing an employee delivery program. The retailer is also piloting a push in its same-day service in certain markets, while retail rival Target just landed a partnership to do so.

Last September, Wal-Mart purchased e-retailer Jet.com, bringing the website's founder, Marc Lore, to its team. Its e-commerce growth has been accelerating ever since, showing little sign of slowing. These days, Wal-Mart and Amazon.com are neck and neck on pricing.

"As Walmart is a key player across most back-to-school/back-to-college product categories, and we are in the heart of those seasons, we would expect further promotional activity in Q3, with smaller retailers to feel increased levels of stress as Walmart and Amazon continue their battle over market share," said Charlie O'Shea, Moody's lead retail analyst.

In its fiscal first quarter, Wal-Mart said its grocery business continued to improve across U.S. stores. CFO Biggs told CNBC on Thursday the retailer is pleased with what it's been doing in the food business, and "online grocery continues to grow rapidly."

During the second quarter, food categories saw their strongest quarterly comparable sales performance in five years, Wal-Mart said.

"One of the particular areas of success for Walmart is grocery," GlobalData Retail Managing Director Neil Saunders wrote in a note to clients. "Our data show continued gains in customer share, even in areas where discounters like Aldi have expanded. ... [Wal-Mart] is one of the few firms that have the firepower to cope with the push towards compressed prices and margins."

The retailer completed remodels of 283 stores globally in the second quarter, and expanded its online grocery service to include more than 900 locations in the U.S. alone.

Retail rival Target on Wednesday reported better-than-expected digital sales growth, as it saw more shoppers returning to its stores and online for "quick trips" — ringing up smaller purchases, but more frequently.

As of Wednesday's market close, shares of Wal-Mart have climbed about 11 percent over the past 12 months. This far outpaces the S&P 500 Retail ETF's (XRT) declines of about 15 percent over the period.