我有一些 PHP 脚本、HTML 表单和 JS 代码(AJAX):
if(isset($_POST['site'])){
$homepage = file_get_contents("http://".$_POST['site']);
preg_match('%<meta.*name="keywords".*content="(.*)"\s+/>%U', $homepage, $regs);
if(count($regs))
{
$myString = implode('', $regs );
print_r($myString);
}
}
?>
<form id=payment method="post" name="forma1">
<label for=name>ENTER www.bbc.com:</label>
<input id="name" type=text placeholder="Write here..." name="site">
<input type="submit" value="START" name="searchbutton" id="sb">
</form>
<script src="jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#payment').submit(function(e){
e.preventDefault();
$.ajax({
type: "POST",
url: $(this).attr('action'),
data: $(this).serialize(),
dataType: 'json',
success: function(data)
{
alert("OK, AJAX IS WORKING");
}
});
});
});
</script>
没有 JS 代码一切正常。PHP 脚本也可以正常工作,当我单击按钮时,在收到所需信息后。但是当我尝试使用 AJAX 并单击按钮时,我没有任何操作。我认为,thant JS 代码是错误的,也可能是 PHP。请问各位高手,谁能帮我修改一下代码?