0

我有这样的链接我需要在带有城市 ID 或名称的对话框中显示城市的详细信息,但无法发送数据

<a class="dot"  style="top:110px;  left:145px;" continent="NA"  id="1"  name="1"></a>

我需要单击时显示弹出对话框,但单击后对话框未打开

    <script language="javascript" type="text/javascript">
$('a.dot').click(function(){
var vid=$(this).attr('id');
var vname=$(this).attr('name');
var vcity=$(this).attr('city');
$.ajax({
type : GET,
data:{id : vid , name : vname , city : vcity},
url : "ajax.php",
success : function(data){
$('#dialog-message').html(data);
}

});
});
</script>

<a class="dot" style="top:110px; left:145px;" continent="NA" id="1" name="1" city="teh"></a>

<div id="dialog-message">
</div>

ajax.php 代码是:

if(isset($_GET)){
echo '<script>
    $(function() {
        $( "#dialog-message" ).dialog({
            modal: true,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });
    });
    </script>
    <div id="dialog-message">
   ' . $_GET[name]  . ',' . $_GET[id] . ',' . $_GET[city] . '
    </div>
';
}
4

3 回答 3

0
   $(document).ready(function() {

    $('.dot').click(function(){
    var vid=$(this).attr('id');
    var vname=$(this).attr('name');
    var vcity=$(this).attr('city');
    $.ajax({
    type : "GET",
    data:{id : vid , name : vname , city : vcity},
    url : "ajax.php",
    success : function(data){
    $('#dialog-message').html(data);
        $( "#dialog-message" ).dialog();
    }

    });
    });
    });

类型:“GET” 不是类型:GET

ajax.php

if(isset($_GET)){
echo  $_GET[name]  . ',' . $_GET[id] . ',' . $_GET[city] ;
}
于 2012-10-17T09:51:21.753 回答
0

您的 PHP 代码似乎正在创建<div id="dialog-message">另一个<div id="dialog-message">. 尝试更改idPHP 生成的内容,并更改 PHP 中的脚本以匹配新的id.

于 2012-10-17T09:51:50.693 回答
0

Ajax .get 可以轻松完成这项工作:

//This is a Click even. It fires when you click the (<a class="dot">CLick</a>)
<script language="javascript" type="text/javascript">

$(document).ready(function() {

$('.dot').click(function(){

var vid=$(this).attr('id');

var vname=$(this).attr('name');

var vcity=$(this).attr('city');

$.get("ajax.php?id="+ vid +"&name="+ vname + "&city=" + vcity, function(data){

    $('#dialog-message').html(data);

    $( "#dialog-message" ).dialog({

            modal: true,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

    });
});
});

</script>



//This is a load even. It fires when the page is loaded
<script language="javascript" type="text/javascript">

$(document).ready(function() {

var vid=$(this).attr('id');

var vname=$(this).attr('name');

var vcity=$(this).attr('city');

$.get("ajax.php?id="+ vid +"&name="+ vname + "&city=" + vcity, function(data){

    $('#dialog-message').html(data);

    $( "#dialog-message" ).dialog({

            modal: true,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

    });

});

</script>

    <a class="dot" style="top:110px; left:145px;" continent="NA" id="1" name="1" city="teh">Click Here</a>

    <div id="dialog-message" style="display:none;">
    </div>

ajax.php

if(isset($_GET)){
echo  $_GET[name]  . ',' . $_GET[id] . ',' . $_GET[city] ;
}
于 2012-10-17T09:56:53.213 回答