为什么使用jQuery的Ajax请求无法处理?

时间:2013-11-27 09:47:47

标签: javascript php jquery sql ajax

这是事实,我有这2个文件:

页面上有一个空div #responsecontainer,最后是这个脚本:

<script type="text/javascript">
jQuery(document).ready(function ($) {
    $('#tabs').tab();
    $("#datatableindirizzi").click(function() {

    $.ajax({

        type: "GET",
        url: "display.php",
        dataType:"html",
        success: function(response){
            $("#responsecontainer").html(response);
        error :  function(textStatus) {
            alert(textStatus);
        } 
        }
    })
})
});

(div容器位于bootstrap选项卡下,但我不认为这是一个问题)

和display.php文件:

<?php

//include presentation file

$con = mysql_connect("*********" , "*******" , "********" );
   if(!$con) { 

       die('could not connect'. mysql_error());

   }

   mysql_select_db("minigest_dev" , $con);
   $query = "   SELECT * FROM anag_c_indirizzi";
   $result = mysql_query($query, $con);

     $row = mysql_fetch_row($result); 

    echo " <div class='controls controls-row'>
                <div class='span2'>
                    <label>c/o</label>
                    <input type='text'  class='input-small' placeholder='DA METTERE' value=''>
                </div>
                <div class='span3'>
                <label>Indirizzo</label>
                <input type='text' class='input-large' placeholder='Digita indirizzo..' value='$row[6]'>
                </div>
                <div class='span2'>
                    <label>n°</label>
                    <input type='text'  class='input-small' placeholder='num' value='$row[7]'>
                </div>
            </div>
            <div class='controls controls-row'>
                <div class='span3'>
                 <label>
                     Località
                 </label>
                 <select> 
                        <option>1 da mettere</option>
                        <option>2</option>
                        <option>3</option>
                        <option>4</option>                       
                  </select>
                </div>
                <div class='span2'>
                    <label>C.A.P</label>
                    <input type='text' class='input-small' placeholder='cap' value='$row[8]'>
                </div>
                 <div class='span2'>
                    <label>Prov</label>
                    <input type='text' class='input-mini' placeholder='cap' value='$row[11]'>
                </div>
                <div class='span3'>
                    <label>Nazione</label>
                    <input type='text' placeholder='Inserisci nazione..' value='$row[12]'>
                </div>

            </div> 
            <div class='controls controls-row'>
                <div class='span3'>
                    <label>Telefono</label>
                    <input type='text' placeholder='numero di telefono' value='$row[13]'>
                </div>
                <div class='span3'>
                    <label>Fax</label>
                    <input type='text' placeholder='numero fax' value='$row[14]'>
                </div>
                <div class='span3'>
                    <label>Mail</label>
                    <input type='text' placeholder='indirizzo mail' value='$row[15]'>
                </div>

            </div>
            <div class='controls controls-row'>
                <div class='span3'>
                    <label>Web</label>
                    <input type='text' placeholder='sito web' value='$row[16]'>
                </div>
            </div>";

&GT;

为什么当我点击应该触发ajax脚本的表时没有任何反应???数据库调用都是正确的。我错过了什么?

1 个答案:

答案 0 :(得分:0)

你有一个js错误...

更改此

    success: function(response){
        $("#responsecontainer").html(response);
    error :  function(textStatus) {
        alert(textStatus);
    } 
    }

    success: function(response){
        $("#responsecontainer").html(response);
    },
    error :  function(textStatus) {
        alert(textStatus);
    }