ajax表单找不到javascript函数

时间:2011-05-12 18:29:28

标签: javascript jquery ajax forms function

无论我尝试多少东西,我似乎都无法弄清楚我在做错什么。我已经通过Google查看了相关问题,但没有找到任何具体内容。希望有人可以帮助我。

脚本通过调用音乐专辑列表的外部.js文件运行,然后列出通过ajax选择的专辑的歌曲。然后,用户可以编辑删除歌曲。一切正常,直到我通过表格提交编辑过的信息。当我单击提交按钮时,我收到Web开发人员错误“updateSong不是函数”

以下是表格:

    <?php
    include("database.php");

    $song =  $_GET['song'];

    $query = "SELECT * FROM song INNER JOIN genre ON song.gID = genre.gID INNER JOIN album ON song.alID = album.alID WHERE sID = '$song'";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)) {
    echo ("

    <form action='#' method='POST' name='updateSong' onSubmit='updateSong(\"$song\")'>
    <input name='songName' type='text' value='$row[songName]' />
    <input type='text' id='genreSearch' name='genre' alt='Genre Search' onkeyup='searchSuggest();' autocomplete='off' value='$row[genreName]'/>
    <div id='genre_search_suggest'></div>
    <input name='songURL' type='text' value='$row[songUrl]' />
    <input name='sID' type='hidden' value='$row[sID]' />
    <input name='Submit' type='Submit' value='Update Song' />
    </form>

    ");
    }

    ?>

这是javascript:

    function updateSong(sID) {
if(ajax) {
var song = sID;
alert("2");
ajax.open('get', './song_update.php' + encodeURIComponent(sID));
alert("3");
ajax.onreadystatechange = function() {
handleResponse(ajax);
}
ajax.send(null);
return false;

}
    }

// // EDIT 这是它加载的页面。我删除了这个问题所涉及的不必要的东西。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <link href="artistPageStyle.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="javascripts/artistAjax.js"></script>

    </head>
    <body>

    <div id="mediaPlayerBox">

    <div id="artistAlbumList">
    <?php 
$query = "SELECT * FROM `album` INNER JOIN artist ON album.aID = artist.aID WHERE artist.LoginKey = '$token'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)) {
echo ("<div id='artistAlbumBox'><div id='artistAlbum'><a href='#' onclick='loadAlbum($row[alID])'><img src='$row[albumCover]' width='75px' height='75px' border='0px' ></a></div><div id='artistAlbumLabel'>$row[albumName]</div></div>");
 }
?>
</div>

    </div>

    </body>
    </html>

3 个答案:

答案 0 :(得分:0)

不应该是:onSubmit='updateSong("$song")'

答案 1 :(得分:0)

尝试onSubmit ='return updateSong($ song)'

答案 2 :(得分:0)

它说它不是一个函数,因为它没有加载,你是否在显示页面加载外部脚本?