Hi all.
I have 2 pages:
that provides data from mysql in json encoding if a correct "key" is provided, in my case the "key" sent by method post should be "1".
Link: http://semaffiliate.local/public/api/getemployees
Code in Zend:public function getemployeesAction() { $key = $this->getRequest()->getPost('key'); if (isset($key)) { if ($key == 1) { $employeeModel = new Application_Model_DbTable_Employee(); $employees = $employeeModel->fetchAll()->toArray(); $res = array('status' => 'Success', 'settings' => $employees); } else { $res = array('status' => 'Error', 'message' => 'Access denied, invalid key supplied.'); } } else { $res = array('status' => 'Error', 'message' => 'Access denied, you must supply a key.'); } $json = Zend_Json_Encoder::encode($res); header('Content-Type: application/json; charset=utf-8'); print Zend_Json::prettyPrint($json); }
that has a form, a div where the result should come and an ajax request.
Link: http://soccerstatistics.local/public/api/index2
Code:<form id="myform" action="#"> <input id="mytext" type="text" name="key" size="10" placeholder="Type the key here..." /> <input id="mysubmit" type="submit" value="OK" /> </form> <div id="mydata"></div> <script type="text/javascript"> $(document).ready(function(){ $('#myform').submit(function(){ var postData = "key=" + $('#mytext').value(); $.ajax({ type: "POST", url: "http://semaffiliate.local/public/api/getemployees", data: postData, success: function(data) { $('#mydata').html(data); }, error: function() { alert('Error'); } }); }); }) </script>
After I submit the form, the link becomes: http://soccerstatistics.local/public/api/index2?key=1# and nothing is returned.
Please advise what can be the problem. Thanks.