How can I retrieve multiple echoes in my PHP to my success:function

in my php I echoed

        //sql query here
        foreach($user as $values){
            echo $values['id'];
            echo $values['name'];
            echo $values['email'];
            echo $values['loc'];
        }

in my $.post

success:function(msg){
//what to put here to be able to retrieve the values?
}

and in my html

 <td id="idField"></td><td id="nameField"></td><td id="emailField"></td><td id="locField"></td>

How should be done in a right way? The output should display the specified columns from a table and should display a numbers of rows depends from the query result.

Answers


PHP

echo json_encode($user);

jQuery

success:function(msg){
  $('#idField').html(msg.id);
  $('#nameField').html(msg.name;
  // etc      
}

You really should learn how to use documentation, google, SO and online help. There is thousands of tutorials, docs, help how to do it. Just make some research before you ask for help.

Get data from php array - AJAX - jQuery


Need Your Help

Do I need FileDescriptor “sync” and MappedByteBuffer “force”?

java nio memory-mapped-files

When I want to make sure that the changes of a MappedByteBuffer should be synced back to disc do I need randomAcccessFile.getFD().sync() or mappedByteBuffer.force() or both? (In my simple tests non...

Windows Phone CollectionViewSort not showing anything

c# xaml windows-phone-8 collectionviewsource

I am trying to develop a page in a WP8 app which has a search box at the top and a list of items that match the search below, updating as the search box updates. Pretty straightforward, right? Exce...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.