0

私は次のコードを持っています:

<h3> Your Profile </h3>
The information below is what we have on file for you.

<form id="profileform" name="profileform" action=""> 
<table>

<?php
$profile_array = select_profile_data($_SESSION['id']);
while (list($key, $value) = each($profile_array)) {
if(!in_array($key,$dont_display_list,true)) {
 echo '<tr><td>'.$key.'</td><td><input type="text" name=' . $key . ' value="'.$value.'"</td></tr>';
}
}
?>
</table>
<input type="button" value="submit changes" name="submit" onClick="button_click('profileform')">
</form>

<script type='text/javascript'>

function button_click(formname) {
var fullselect = formname + " :input";
alert(fullselect);
var values = $(fullselect);
alert(values.size());
$("#content").html('<span>Loading...</span>');
$("#content").load('profile.php', values, function(response, status, xhr) {
        if (status == "error") {
            var msg = "Sorry but there was an error: ";
            $("#content").html(msg + xhr.status + " " + xhr.statusText);
        }
    });
}

「fullselect」でのアラートは、予想されるjqueryセレクター文字列'profileform:input'を示しています。ただし、私の「values」変数は常に「0」のサイズを返します。フォームには間違いなく「入力変数」がありますが。私がここで間違っているところについて何か考えはありますか?

ありがとう、

4

1 に答える 1

1

次の形式であるため、変数#の先頭からを見逃しました。formnameid

var fullselect = "#" + formname + " :input";

また、values変数はjQueryオブジェクトの配列になるため、メソッドを使用してPHPに渡すことはできませんload()。最善serialize()の方法は、フォーム全体にそれを渡すことです。

var values = $(fullselect).serialize();
于 2012-04-09T14:52:17.803 に答える