0

I have a jquery as HTML form as below. I am trying to display some documents required and show a div when the user changes the options, depending on the option value.

<select id="constitution_id" class="form_select_constitution">
    <option value="1">First</option>
    <option value="2">Second</option>
</select>

And the javascript:

$('.form_select_constitution').change(function(){
      var cid = $(this).val();
      if(cid > 2 ) {
        $('#appDiv').show();    
      }else{
        $('#appDiv').hide();    
      }
      data = 'cid='+cid;
      url = 'business_documents_available.php';


      $.ajax({
        type: "GET",
        url : url;
        data : data,
        //dataType: "json",
        error:function(resp){
                alert('Error !');
            },
            success: function(resp){
                alert(resp);
        //show_docs(resp);
            }
      });

});

function show_docs(resp) {
     //$('.json_resp_docs').html(resp.documents); 
}

And the business_documents_available.php is :

<?php
    include_once('include/config.php');
    include_once('validate.php');
    include_once('applicants.php');

    $cid = $_GET['cid'];
    $sql = "SELECT * FROM doc_vehical_loan_list WHERE constitution_type = '$cid'";
    $result = $db->executeQuery($sql);

    $result_json = json_encode($result);
    //var_dump($result_json);
    //return $result_json;
    return 'HII';
?>

Though showing and hiding the div id appDiv is working , I am not getting any alert from the ajax response ! Whats happening?

Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
user2625357
  • 53
  • 1
  • 3
  • 12
  • any error in your browser console – Arun P Johny Dec 19 '13 at 09:15
  • 1
    @user2625357 check in your browser's network tab whether your ajax call is woerking or not. you can get response codes –  Dec 19 '13 at 09:17
  • check your browser console for javascript errors. – Anish Dec 19 '13 at 09:21
  • **Danger**: You are **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that you need to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Dec 19 '13 at 09:21
  • Where's the problem? Do some basic debugging. Check your error console to see if there are any error messages. Check your developer tools' net tab to see if the HTTP request is made, and if it is going where you expect, and if the response is what you expect. – Quentin Dec 19 '13 at 09:23
  • you cant directly return 'return HII' –  Dec 19 '13 at 10:05
  • i thinnk passed data might be causing the problem update data like data:{cid:cid}, – Rudresha Parameshappa Dec 19 '13 at 11:45

2 Answers2

0

Use

echo json_encode($result);
exit;

in business_documents_available.php in place of

return 'HII';
Rohit
  • 403
  • 3
  • 15
0

a simple workout

html

<html>
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<select id="constitution_id" class="form_select form_select_constitution">
<option value="1">First</option>
<option value="2">Second</option>
</select>
<script type="text/javascript">
$('.form_select_constitution').on("change",function() {

        var id = "id";  //just for reference     

        $.ajax({     
        type: "GET",   //use any kind of verb
        data: "id="+id,  //just for reference   
        url: "business_documents_available.php",
        success: function(html){
        alert(html);
        }
   });

});
</script>
</html>

php page

<?php
   echo "hey im reached";
?>