0

したがって、私の問題は、ここで関数(データ)部分でエラーが発生していることです。理由はわかりません-dreamweaverでエラーが発生し、コードでエラーを示す赤いマークが表示されるだけです

<script language="javascript" type="text/javascript">
    $("#dropdown").on('change', function() {//when you select something from the dropdown function run and will switch the data
        $.post("backgroundScript.php", {
                uid: $(this).val()
            } function(data) { // right here is the error im getting
                 $("#first").val(data.first);
               $("#last").val(data.last);
               // etc.;
            }, 'json'
        );
    });
</script>

私がやろうとしているのは、db heres の残りのコードからフォームでオートフィルを作成することです

try {  
  # MySQL with PDO_MYSQL  
  $DBH = new PDO("mysql:host=$hostname;dbname=$database", $username, $password);  
  $DBH->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );

  //$DBH->prepare('SELECT first FROM contacts');
}  
catch(PDOException $e) { 
    echo "I'm sorry, I'm afraid I can't do that.";  
    file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);   
}  
//get query
$FNresult=$DBH->query('SELECT first FROM contacts'); 
//set fetch mode
$FNresult->setFetchMode(PDO::FETCH_ASSOC);

$dropdown = "<select name='contacts' id='contacts' >";

while($row =$FNresult->fetch()) {

  $dropdown .= "\r\n<option value='{$row['first']}'>{$row['first']}</option>";
 // echo getLN();

}

$dropdown .= "\r\n</select>";

echo $dropdown;

//}
/*
//                  Get last name

function getLN(){
    $query = "SELECT last FROM contacts";
    $LNresult=mysql_query($query);

    $last;
    while($row = mysql_fetch_assoc($LNresult)) {

        $last = "{$row['last']}";

    }
    echo $last;
}//end getLN
*/

$DBH = null; 
?>
<!-- javascript on client-side -->
<script language="javascript" type="text/javascript">
    $("#dropdown").on('change', function() {//when you select something from the dropdown function run and will switch the data
        $.post("backgroundScript.php", {
                uid: $(this).val()
            } function(data) {
                 $("#first").val(data.first);
               $("#last").val(data.last);
               // etc.;
            }, 'json'
        );
    });
</script>


<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js">
//$("#[id]");
</script>

<form action="insert.php" method="post">
First Name: <input type="text" id="first" name="first"><br>
Last Name: <input type="text" id="last"><br>
Phone: <input type="text" id="phone"><br>
Mobile: <input type="text" id="mobile"><br>
Fax: <input type="text" id="fax"><br>
E-mail: <input type="text" id="email"><br>
Web: <input type="text" id="web"><br>
<input type="Submit">
</form>

他に何か必要な場合はお知らせください。本当にありがとうございます。

4

1 に答える 1

0

あなた,の「データ」部分の後に欠けています.post()

<script>
    $("#dropdown").on('change', function() {
        $.post(
            "backgroundScript.php", 
            {
                uid: $(this).val()
            }, // you were missing this comma
            function(data) {
                $("#first").val(data.first);
                $("#last").val(data.last);
                // etc.;
            }, 
            'json'
        );
    });
</script>

の形式.post()は次のとおりです。

$.post(url, [data], [callback], [callback type])、角括弧内のものはオプションです。

于 2012-08-07T02:38:41.120 に答える