I am creating a module that takes an SKU via a GET requests and returns a JSON object with some of that product’s attributes.
My indexController function code looks like this
public function pinboardgetitemsAction(){
$sku = $_GET[sku];
$product = Mage::getModel('catalog/product')
->loadByAttribute('sku', $sku);
$fullItem = array();
$fullItem[0] = $product->getName();
$fullItem[1] = $product->getFormatedPrice();
$fullItem[2] = $product->getSmallImageUrl();
echo json_encode($fullItem);
}
When I load this request in a browser it correctly returns the JSON object
http://www.jinkou.info/pinboard/index/pinboardgetitems?sku=50065
However when I do an AJAX request (I am using jQuery) $sku is not set and an Fatal error is thrown.
The easiest way to see this behaviour is by using http://hurl.it
Aside from my typo comment, the appropriate way to access params is through the request object: