我有这样的链接 我需要在城市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>
';
}
答案 0 :(得分: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”NOT type:GET
ajax.php
if(isset($_GET)){
echo $_GET[name] . ',' . $_GET[id] . ',' . $_GET[city] ;
}
答案 1 :(得分:0)
您的PHP代码似乎是在另一个<div id="dialog-message">
内创建<div id="dialog-message">
。尝试更改PHP生成的id
,并更改PHP中的脚本以匹配新的id
。
答案 2 :(得分: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] ;
}