Apply for Zend Framework Certification Training

Jquery




Question (1)  if the data is send by controller to js using ajax using format json
      then in js how to access array json data 

	$data['state'] = $state;
        $data['city'] = $city;
        $data['streetaddress'] = $streetaddress;
        $data['pincode'] = $pincode;
	print_r(json_encode($data));


Answer  (1)

	jQuery.ajax({
                        type: "POST",
                        dataType: "json",
                        url: baseUrl + 'index/geolocationaccess', 
                        data: JSON.stringify(requestData),
                        success: function(response) {
                            document.getElementById("sel1").value = response.state;
                            document.getElementById("street_add").value = response.streetaddress;
                            document.getElementById("pin_code").value = response.pincode;
                            LAT1 = response.LAT1;
                            LNG1 = response.LNG1;
                            LAT2 = response.LAT2;
                            LNG2 = response.LNG2;
                            getChangeAreaForGeolocation(LAT1,LNG1,LAT2,LNG2);
                            

                        }
                    });
Q no 2   if  Data is returned by Ajax request is  like this (ABOVE)
               {"pincode_details":{"aadhaar_pincode_id":"1","aadhar_pincode":"231501",
               "pincode_devision":"Mirzapur","pincode_region":"Allahabad","pincode_area":"Sadar",
               "pincode_district":"Mirzapur","pincode_circle_name":"Uttar Pradesh",
               "pincode_remarks":"Local","pincode_circle_code":"UK",
              "pincode_gst_state_code":"UP"},"status":"success"}

Ans To display at front end 
              response.pincode_details['pincode_devision'];                                    

< Display Data Using Php Mysql Jquery in Json Format Access json php jquery arrays objects >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top