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的值?
答案 0 :(得分:2)
不存在名称为this
的标记。您必须写$(this)
而不是$('this')
...
但这也是错误的,您必须将this
(元素)传递给函数,然后将其用作“ selector ”:
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>";
答案 1 :(得分: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;
}
答案 2 :(得分:0)
删除数据类型'script'。您正从请求中获取html,因此jquery应该为您解析它
答案 3 :(得分:-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>";