2

The response text I am getting after ajax call.

$ Array(
    [0] => Array
        (
            [trade_type] => Carpentry
            [active_status] => 0
            [work_order_received] => 8912629
            [fault_type] => 
        )

    [1] => Array
        (
            [trade_type] => Carpentry
            [active_status] => 1
            [work_order_received] => 8912629
            [fault_type] => 
        )

)

As this has multiple entries how to loop through this and get data. for example : var trade_type = carpentry;

I tried using JSON.pase. but this started to return single character at a time

My Php code which is returning Ajax data.

public function get_job_details_by_workorder(){

$workorder = $this->input->post('work_order');
$query=$this->db->query("select trade_type,active_status,work_order_received,fault_type from nrm_doc_header where work_order_received='$workorder'")->result_array();

print_r($query);
}
0

2 Answers 2

1

You need to json_encode() it in php first so it gets sent as as [{"trade_type":"Carpentry"...}]

echo json_encode($myArray);
Sign up to request clarification or add additional context in comments.

5 Comments

Array ( [0] => Array ( [trade_type] => Carpentry [active_status] => 0 [work_order_received] => 8912629 [fault_type] => ) [1] => Array ( [trade_type] => Carpentry [active_status] => 1 [work_order_received] => 8912629 [fault_type] => ) ) I am receiving from Json encode only
What am I supposed to see in that comment that is different?
That doesn't make sense. Need to show your basic php and how you get that
I have added my Php code. Sorry I am new to Stackoverflow so the way I have asked the question might be not right.
So change print_r to echo json_encode($query); No worries about being new. Takes a bit of getting used to how it all works
0

I was missing dataType:Json in my ajax call. so i was getting return in text format.so was not able to parse it.

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.