PDA

View Full Version : Need help regarding ajax with JsonStore



jagadeesheie
18 May 2010, 12:11 AM
Hi,
i need an example program for storing ajax responsetext into a json store..... i urgently need this for one of my projects.Actually i got my store loaded with data but when retrieving each letter is retrieved as a single element.. so anybody can help on this??


thanks in advance,
Jag

jagadeesheie
18 May 2010, 12:13 AM
Ext.Ajax.request({

url: '/o/secure/secureScripts/shop/shop.php',
params:{"action":"getitem", "prodId":prodid }, method:'POST',
loadMask:true,

success: function( responseObject ) {
LOOKHERE =Ext.encode(responseObject);
mystore=new Ext.data.JsonStore({
fields:['vendorNr'],
data:[LOOKHERE],
autoLoad:true
});
},
failure: function( responseObject ) { alert( "There was a problem connecting to the Internet" ); }
});

wm003
18 May 2010, 12:13 AM
mmh, how did you setup your jsonstore and what responsestring is return exactly from the server?

jagadeesheie
18 May 2010, 12:33 AM
{"tId":10,"status":200,"statusText":"OK","responseText":"\r\n\r\n\r\n{\"identifier\":\"true\",\"items\":{\"active\":1,\"comissionId\":null,\"displayOptionFlag\":null,\"displayPriority\":0,\"fixedShipping\":\"N\",\"freeStdShipping\":\"\",\"image\":\"\\/images\\/products\\/vendors\\/1066\\/large\\/org-tdn76aq.jpg\",\"image1\":\"org-tdn76aq.jpg\",\"image10\":null,\"image2\":null,\"image3\":null,\"image4\":null,\"image5\":null,\"image6\":null,\"image7\":null,\"image8\":null,\"image9\":null,\"includeFilter\":\"all\",\"itemCost\":46.99,\"itemName\":\"Big Student Backpack by JanSport?\",\"listPrice\":0,\"modelNr\":\"\",\"offerTypeId\":1,\"productId\":586,\"productIdIn\":null,\"productOptions\":null,\"productType\":1,\"quantityAvailable\":99999,\"sellingPrice\":48.5,\"shippingText\":null,\"shortDescription\":\"For the overworked student who never has enough space for the important stuff, the JanSport? Big Student Backpack is the perfect tool for you!\",\"skuNr\":\"Org-TDN76AQ\",\"standaloneName\":\"JanSport? Backpack\",\"tabInformation\":[{\"fontColor\":\"\",\"fontStyle\":null,\"orderId\":0,\"prodText\":\"<p><span style=\\\"FONT-SIZE: small; FONT-FAMILY: trebuchet ms,geneva\\\"> The White Calypso Blue Tree Flower design backpack not only looks great it also gives you tons of room to stay organized. With 2 large main compartments, it's designed for flexible storage and gives you plenty of space for up to 5 textbooks, laptop computer, binders, gym clothes and numerous school accessories.&nbsp;<\\/span><\\/p><p><span style=\\\"FONT-SIZE: small; FONT-FAMILY: trebuchet ms,geneva\\\"> With a front utility pocket that includes an audio electronics organizer and a quick-find cell phone pocket on the front side, this backpack makes it easy to take your gear with you and keeps everything in its place for easy access.&nbsp;<\\/span><\\/p>\\n<p><span style=\\\"FONT-SIZE: small; FONT-FAMILY: trebuchet ms,geneva\\\">The adjustable and ergonomic S-curve shoulder straps and web haul loop provide different carrying options for your convenience. The fully padded back panel provides unbeatable cushioning and comfort. The heavy duty 600 denier polyester construction is backed by the trusted JanSport? name, and will continue to carry your heavy workload for years to come!&nbsp;<\\/span><\\/p>\",\"tabText\":\"The Big Picture\"},{\"fontColor\":\"\",\"fontStyle\":null,\"orderId\":1,\"prodText\":\"<ul>\\n<li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Thick plastic body for extra stability<\\/span><\\/span><\\/li>\\n<li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Durable 600 denier polyester construction &nbsp;<\\/span><\\/span><\\/li>\\n<li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Ergonomic S-curve shoulder straps &nbsp;<\\/span><\\/span><\\/li>\\n<li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> 2 large main compartments for versatile storage &nbsp;<\\/span><\\/span><\\/li><li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Front utility pocket with audio electronics organizer&nbsp;<\\/span><\\/span><\\/li><li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Pleated front stash pocket &nbsp;<\\/span><\\/span><\\/li><li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Quick-find cell phone pocket &nbsp;<\\/span><\\/span><\\/li><li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Fully padded back panel for cushioning comfort<\\/span><\\/span><\\/li><li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> \\nWeb haul loop <\\/span><\\/span><\\/li><li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\">Color: White Calypso Blue Tree Flower &nbsp;<\\/span><\\/span><\\/li> <li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Size: 17 1\\/4\\\"tall x 13\\\"wide x 10\\\"deep<\\/span><\\/span><\\/li><li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\"> Capacity: 2100 cubic inches.<\\/span><\\/span><\\/li> <li><span style=\\\"FONT-FAMILY: trebuchet ms,geneva\\\"><span style=\\\"FONT-SIZE: small\\\">Fits:\\n3-5 textbooks,\\nLaptop computer,\\n1-3 large binders,\\nPaperback books,\\nSpiral notebooks,\\nCalculator,\\nPens and pencils,\\nBag lunch,\\nCellphone,\\nMP3 Player,\\nGym clothes, or\\nSweatshirt\\n &nbsp;<\\/span><\\/span><\\/li>\\n<\\/ul>\",\"tabText\":\"Details\"}],\"tagText\":\"\",\"variation\":\"White Calypso blue\",\"variationOrder\":0,\"vendorNr\":1066,\"weight\":0.0},\"label\":\"\"}","responseXML":null}

jagadeesheie
18 May 2010, 12:34 AM
while i retrieve using
var daata=mystore.reader.jsonData;

but my problem is i cant get the details above as a json data..instead it works like normal array..
pls help on this.

wm003
19 May 2010, 3:33 AM
responseObject.responseText holds the JSON on Ajax return, so you might try


Ext.Ajax.request({

url: '/o/secure/secureScripts/shop/shop.php',
params:{"action":"getitem", "prodId":prodid }, method:'POST',
loadMask:true,

success: function( responseObject ) {
mystore=new Ext.data.JsonStore({
fields:['vendorNr'],
data:responseObject.responseText,
autoLoad:true
});
},
failure: function( responseObject ) { alert( "There was a problem connecting to the Internet" ); }
});
Anyway you have some weird linefeeds "\r\n\r\n\r\n" at the beginning of your responseText JSON. I guess your shop.php has some empty lines before sending code back to the client (be sure the very first line in your shop.php starts with "<?php" without any lione feeds or spaces