jQuery $.ajax request of dataType json will not retrieve data from PHP script

前端 未结 8 939
情话喂你
情话喂你 2020-11-30 03:31

I\'ve been looking all over for the solution but I cannot find anything that works. I am trying to get a bunch of data from the database and then via AJAX autocomplete input

相关标签:
8条回答
  • 2020-11-30 04:04

    In addition to McHerbie's note, try json_encode( $json_arr, JSON_FORCE_OBJECT ); if you are on PHP 5.3...

    0 讨论(0)
  • 2020-11-30 04:17
    Try this...  
      <script type="text/javascript">
    
        $(document).ready(function(){
    
        $("#find").click(function(){
            var username  = $("#username").val();
                $.ajax({
                type: 'POST',
                dataType: 'json',
                url: 'includes/find.php',
                data: 'username='+username,
                success: function( data ) {
                //in data you result will be available...
                response = jQuery.parseJSON(data);
    //further code..
                },
    
        error: function(xhr, status, error) {
            alert(status);
            },
        dataType: 'text'
    
        });
            });
    
        });
    
    
    
        </script>
    
        <form name="Find User" id="userform" class="invoform" method="post" />
    
        <div id ="userdiv">
          <p>Name (Lastname, firstname):</p>
          </label>
          <input type="text" name="username" id="username" class="inputfield" />
          <input type="button" name="find" id="find" class="passwordsubmit" value="find" />
        </div>
        </form>
        <div id="userinfo"><b>info will be listed here.</b></div>
    
    0 讨论(0)
提交回复
热议问题