Javascript PHP数据在AJAX中的成功?

Javascript PHP数据在AJAX中的成功?,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我试图通过AJAX运行一个非常基本的PHP代码,并将数据从PHP页面返回到AJAX中 然而,我并没有从PHP页面中获得任何AJAX成功,这让我感到非常困扰 这是AJAX代码: $(document).ready(function(){ $(function(){ $('#form-post').on('submit', function(e){ // prevent native form submission here e.preventDefault

我试图通过AJAX运行一个非常基本的PHP代码,并将数据从PHP页面返回到AJAX中

然而,我并没有从PHP页面中获得任何AJAX成功,这让我感到非常困扰

这是AJAX代码:

$(document).ready(function(){
$(function(){
    $('#form-post').on('submit', function(e){

        // prevent native form submission here
        e.preventDefault();

        // now do whatever you want here
        $.ajax({
            type: $(this).attr('method'), // <-- get method of form
            url: $(this).attr('action'), // <-- get action of form
            data: $(this).serialize(), // <-- serialize all fields into a string that is ready to be posted to your PHP file
            beforeSend: function(){
                //$('#result').html('<img src="loading.gif" />');
            },
            success: function(data){
                $('#messageme').html(data);
            }
        });
    });
});
});
$(文档).ready(函数(){
$(函数(){
$(#form post')。关于('submit',函数(e){
//禁止在此处提交本机表单
e、 预防默认值();
//现在你想怎么做就怎么做
$.ajax({

键入:$(this).attr('method'),//请尝试以下操作:只需将
type=“button”
更改为
type=“submit”


无标题文件




$(文档).ready(函数(){ $(函数(){ $(#form post')。关于('submit',函数(e){ //禁止在此处提交本机表单 e、 预防默认值(); //现在你想怎么做就怎么做 $.ajax({
键入:$(this).attr('method'),//请尝试以下操作:只需将
type=“button”
更改为
type=“submit”


无标题文件




$(文档).ready(函数(){ $(函数(){ $(#form post')。关于('submit',函数(e){ //禁止在此处提交本机表单 e、 预防默认值(); //现在你想怎么做就怎么做 $.ajax({
键入:$(this.attr('method'),//尝试此$('#messageme').val(数据);添加数据类型:'html'@AVM,不,很遗憾我什么都没有!那么如何调试它?您必须学习如何调试它客户端和服务器端。是否启动提交处理程序?是否调用了成功回调?错误回调如何?URL路径如何?是否检查了网络选项卡?等等…尝试此$('#messageme').val(数据);添加数据类型:'html'@AVM,不,不幸的是我什么都没有!那么你如何调试它?你必须学习如何调试它客户端和服务器端。提交处理程序启动了吗?成功回调调用了吗?错误回调怎么办?URL路径怎么办?你检查网络选项卡了吗?等等,这看起来很明显…;)天哪,在过去的两个小时里,我一直在努力解决这个问题,事情就这么简单。谢谢你,巴德。@william:请更新我的答案,如果它对你有用的话:)@Priyank,我确实试图更新它,伙计,但它说我需要15个声望才能更新答案!但我接受了你的答案。:)@威廉:嘿,现在你可以投票支持我的答案了,现在你的声誉已经超过了15。所以请投票支持:)等等,这看起来很明显…;)天哪,我在过去的两个小时里一直在想这个问题,就这么简单。谢谢巴德。@william:请投票支持我的答案,如果它对你有用的话:)@普里扬克,我确实想投票表决,伙计,但上面说我需要15个声望才能投票表决一个答案!但我接受了你的答案。@william:嘿,现在你可以投票表决我的答案了,现在你的声望超过了15。所以请投票表决:)
    <form id="form-post"  action="post-code.php" method="post" >
<input type="hidden" value="Post" name="submit" />
<input type="text" class="inp-form" name="postcode" id="postcode" placeholder="Enter Post Code " /><br  /><br  /><input type="text" id="messageme"  /><br  /><br  />
<input id="findAd" type="button" value=" Search For Address"  />
</form>
<?php

$street = "some";
    echo $street;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>

<body>
<form id="form-post"  action="post-code.php" method="post" >
<input type="hidden" value="Post" name="submit" />
<input type="text" class="inp-form" name="postcode" id="postcode" placeholder="Enter Post Code " /><br  /><br  />
<input type="text" id="messageme"  /><br  /><br  />
<input id="findAd" type="submit" value=" Search For Address"  />
</form>
<script>$(document).ready(function(){

$(function(){
$('#form-post').on('submit', function(e){

    // prevent native form submission here
    e.preventDefault();

    // now do whatever you want here
    $.ajax({
        type: $(this).attr('method'), // <-- get method of form
        url: $(this).attr('action'), // <-- get action of form
        data: $(this).serialize(), // <-- serialize all fields into a string that is ready to be posted to your PHP file
        beforeSend: function(){
            //$('#result').html('<img src="loading.gif" />');
        },
        success: function(data){
             alert(data);
            $('#messageme').html(data);
        }
        });
        });
        });
        });
    </script>


    </body>
   </html>