0

This is a web page for student results and 3 fields data i.e stu_class, section, exam is sending to controller and a json array data variable is coming back from controller to this page now i wanted to show that json variable's data on the webpage. So help me how to do so?

$(document).ready(function(){

$('#examination').change(function(){

  var exam = $('#examination').val();
  $('#exam').val(exam);
  });

$('#enter').click(function(){
 var stu_class = $('#stu_class').val();
 var section = $('#section').val();
 var exam = $('#examination').val();

  $.ajax(
     {
       type : "POST",
       dataType: "json",
       url : "<?php echo base_url('index.php/marksheet/student_result_database'); ?>",

       data : {
              stu_class : stu_class,
              section : section,
              exam : exam
          },
       success: function(stu_data)
        {
          var items = [];
          $.each( stu_data, function( key, val ) {   
               items.push( "<li id='" + key + "'>" + val['student'] + "</li>" );
             });

             alert(items);

          }
       });
      });

});

And i need to copy the data of stu_data variable of jquery to php variable $stu_data so that i can run a loop to show the values in below fields like this-

<?php foreach($stu_data as $data): 
echo $data['id']; 
echo $data['student'];

Something like this. So programmers please help me..!

3
  • stu_data is data you just got from PHP. It isn't generated by the client. Why not use it before you send it back? Commented Aug 27, 2014 at 10:42
  • "to show the values" — You're using Ajax. The data is coming back to your JS code, not to the HTML page. Why aren't you just adding them to the DOM with JS? You're alreadying generating HTML from them. Commented Aug 27, 2014 at 10:43
  • You might want to check out: stackoverflow.com/questions/19886553/… Commented Aug 27, 2014 at 10:46

1 Answer 1

1

json_decode($str, true) -> turns a json-object into a php assoc array.

json_decode($str, false) -> turns a json-object into a php object.

Sign up to request clarification or add additional context in comments.

1 Comment

The false is not necessary as the optionals parameters default state is false

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.