1

ajax code:

    function dropdown(){

       $.ajax({
            type: 'POST',
            url: '<?php echo Mage::getUrl('rma/index/view')?>',
            data:   $('#order').serialize()  ,
            success: function(response){
            alert(response);

            }
        });  return false;

        }

response is like this

 Array
 (
  [0] => test
  [1] => 1.0000
  [2] => test
 )

now i want array[0] value how to get specific value?

closed as off-topic by Keyul Shah, Marius Jan 19 '15 at 8:12

  • This question does not appear to be about the Magento e-Commerce platform within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    I think this may be off-topic because this is about javascript in general and not Magento. – Marius Jan 19 '15 at 8:12
2

I assume the action you call in the url returns an array like this:

$response = array('test', 1.0000, 'test');
$this->getResponse()->setBody($response);

You need to return the response as a json, and then you will be able to read it in javascript.

$response = array('test', 1.0000, 'test');
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($response));

Then in your js you can do this:

success: function(response){
    response = response.toJSON();
    var whatYouNeed = response[0]; //this is what you are looking for.
}
0

ND14, I guess that you have print array on this controller and please instead of print array here just return the array as json object.

Array
 (
  [0] => test
  [1] => 1.0000
  [2] => test
 )

Like:

Guess that $result is a array which give the data in array format

$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));

Here: Mage::helper('core')->jsonEncode() is encode an array to json. and $this->getResponse()->setBody() set response

for getting value from data ajax success try this code

     onSuccess:function(transport){
            var response=transport.responseText.evalJSON(true);

}

responseText.evalJSON(true) is valued the json return to json data

you can get data by

console.log(response.0);
console.log(response.1);

console.log(response.0);
console.log(response.2);
  • i am add my controller please tell me how to do this as json because i don't know how to use json – ND17 Jan 19 '15 at 8:12

Not the answer you're looking for? Browse other questions tagged or ask your own question.