0
function submitForm()
{
    $.ajax({
        type: 'GET', 
        url: 'iccrefresh.php', 
        data: $('this').serialize(),
        dataType:'script',
        error: function()
                { $( "#dialog_error" ).dialog( "open" ); },
        success: function()
                { $( "#dialog_success" ).dialog( "open" ); }
            });
    return false;
}

在 PHP 中

echo "<form name='refresh' onsubmit='return submitForm();'>";
echo "<input type='hidden' name='team1' value=$teamx />";
echo "<input type='hidden' name='team2' value=$teamy />";
echo "<input type='submit' name='submit' align='middle' value='Refresh Match Score'/>";
echo "</form>";

有什么原因我不能送第 1 队和第 2 队过去吗?我收到一条成功消息,但 iccrefresh 无法访问团队 1 和团队 2 的值?

4

4 回答 4

2

不存在名为 的标签this。你必须写$(this)而不是$('this')......

但这在这里也是错误的,您必须将this(元素)传递给函数,然后将其用作“选择器”:

function submitForm(form)
{
    $.ajax({
        type: 'GET', 
        url: 'iccrefresh.php', 
        data: $(form).serialize(),
        dataType:'script',
        error: function()
                { $( "#dialog_error" ).dialog( "open" ); },
        success: function()
                { $( "#dialog_success" ).dialog( "open" ); }
            });
    return false;
}

在 PHP 中:

echo "<form name='refresh' onsubmit='return submitForm(this);'>";
echo "<input type='hidden' name='team1' value='$teamx' />";
echo "<input type='hidden' name='team2' value='$teamy' />";
echo "<input type='submit' name='submit' align='middle' value='Refresh Match Score'/>";
echo "</form>";
于 2013-04-12T10:50:55.270 回答
1

您不应将其括在引号中,$('this')会找到标签名称this并且不会引用当前form对象。

改变

data: $('this').serialize(),

data: $(this).serialize(),

此外,您正在使用 javascript 绑定事件,因此您需要显式传递源代码。

html

echo "<form name='refresh' onsubmit='return submitForm();'>";  

Javascript

function submitForm(formobj)
{
    $.ajax({
        type: 'GET', 
        url: 'iccrefresh.php', 
        data: $(formobj).serialize(),
        dateType:'script',
        error: function()
                { $( "#dialog_error" ).dialog( "open" ); },
        success: function()
                { $( "#dialog_success" ).dialog( "open" ); }
            });
    return false;
}
于 2013-04-12T10:51:24.710 回答
0

删除数据类型“脚本”。您正在从请求中返回 html,因此 jquery 应该为您解析它

于 2013-04-12T10:51:39.443 回答
-1

试试这个:

echo "<form name='refresh' onsubmit='return submitForm();'>";
echo "<input type='hidden' name='team1' value='".$teamx."' />";
echo "<input type='hidden' name='team2' value='".$teamy."' />";
echo "<input type='submit' name='submit' align='middle' value='Refresh Match Score'/>";
echo "</form>";
于 2013-04-12T10:50:04.053 回答