1

I am using ajax and the output is an array. I want to break it and display these value in their respective input field by the use of inner.HTML function. Please let me know how can I break it or any function in jQuery so that I could display it in html.

Array
(
    [0] => Array
    (
        [Phone1] => 567567
        [LastName] => Amuso
        [Country] => Australia
        [City] => Sylvania
        [PostalCode2] => 228724
        [PostalCode] => 2227684
        [Email] => [email protected]
        [State] => NSW
        [City2] => Sylvania
        [Country2] => Australia
        [FirstName] => Fabian
        [Id] => 78979
        [StreetAddress1] => 2/20 Evelyn St
        [Address2Street1] => 2/20 Evelyn St
    )

)
2
  • 2
    Have you tried anything? Commented Jan 16, 2012 at 16:52
  • 3
    Kinda hoping those aren't some guy's real contact details... Commented Jan 16, 2012 at 16:54

2 Answers 2

2
var myObject = <?php echo json_encode(myArray[0]); ?>;
console.log(myObject.Phone1);
Sign up to request clarification or add additional context in comments.

Comments

1

Use json_enocde on the array in PHP, then you can use jQuery's parseJSON function to parse it in Javascript.

var arr = $.parseJSON( response );

$( arr[0] ).each( function( i, value ) {
    $( "input[name=" + i + "]" ).val( value );
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.