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>";
为什么我不能派第一队和第二队过去,有什么原因吗?我得到了一条成功的信息,但为什么 ccrefresh 无法访问团队1和团队2的值?
Try this:
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>";
there doesn't exists a tag with the name this
. You have to write $(this)
instead of $('this')
...
But this is also wrong here, you have to pass the this
(the element) into the function and then use it as "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;
}
And in 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>";
You should not enclose this in quotes, $('this')
will find the tag name this
and will not refer to current form
object.
Change
data: $('this').serialize(),
To
data: $(this).serialize(),
Also you are using javascript to bind event, so you need to pass the source explicitly.
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;
}
Remove datatype 'script'. You are getting back html from the request, so jquery should parse it for you