0

I am using the following script

<script>
    $(document).ready(function(){
        $("#view").click(function(){
            var requestId = $("#hdnRequestId").val();

            $.ajax({
                type: "POST",
                url: "enquiryProcess.php",
                data: requestId,
                cache: false,
                success: function(data){
                    console.log(data);
                }
            });

            return false;
        });
    });

My controller function is

<?php
  include('enquiry_function.php');
  $functionObj=new Enquiry();
  if(isset($_POST['requestId']))
  {
    $qt_request_id=$_POST['requestId'];
    $responce=$functionObj->view_enquiry_request($qt_request_id);
    echo json_encode($responce);
  }
?>

And my model function is

class Enquiry
{
      public function view_enquiry_request($qt_request_id)
    {
        $query=mysql_query("SELECT * FROM quote_request WHERE qt_request_id='$qt_request_id'");
        $result=mysql_fetch_assoc($query);
        return $result;
    }
  } 

I did not get any error.But result in console message is empty.How to get the result from php in jquery ajax.please help me.

1
  • Not sure but maybe you need to add a key in data like this: data: "requestId=" + requestId Commented Sep 27, 2016 at 10:10

1 Answer 1

1

Please change

var requestId = $("#hdnRequestId").val();

                    $.ajax({
                        type: "POST"
                        , url: "enquiryProcess.php"
                        , data: {"requestId":requestId}
                        , cache: false
                        , success: function (data) {
                            console.log(data);
                        }
                    });

Pass data as PlainObject or String or Array. See jQuery documentation here http://api.jquery.com/jquery.ajax/

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

1 Comment

The best solution is use JSON as response.

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.