Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
232 views
in Technique[技术] by (71.8m points)

php, jQuery, Lightbox, Ajax GET and POST issue

I have a form in a lightbox (fancybox). I am trying to do an ajax get to run an update to the database. But I do not know why it does not work. The code below is what is in the lightbox:

<div id="timezonelightbox">

<div class="lightboxtitle">Select Time Zone</div>

<form method="get" action="" >

<select name="timezones" id="timezones" class="selecttimezones">

<option value="Africa/Abidjan   ">Africa/Abidjan    </option>

<option value="Africa/Accra     ">Africa/Accra  </option>

<option value="Africa/Addis_Ababa   ">Africa/Addis_Ababa    </option>

<option value="Africa/Algiers   ">Africa/Algiers    </option>

<option value="Africa/Asmara">Africa/Asmara</option>

</select>

<input type="button" id="confirmtimezone" class="confirmtimezone" value="Confirm now" 
onclick="updateTimeZone(); $.fancybox.close();">
</form>

</div>

<script type="text/javascript"> 

        function updateTimeZone(){

                $.getScript('<?echo $site["url"];?>/updateTimeZone.php?timezones=<?echo $_GET["timezones"]?>');

}

        </script>

This is what I have in the called file:

header("content-type:text/js");

if(isset($_GET['timezones'])){

$queryupdatetimezone="UPDATE `Profiles` SET `TimeZone` ='".$_GET['timezones']."' WHERE 
ID=".(int)$_COOKIE['memberID'];

$resultupdatetimezone=mysql_query($queryupdatetimezone) or die("Errore update default timezones: ".mysql_error());

    exit;

}else{

?>alert ('An error occured');<?

}
?>

Everything seems fine when I click the confirm button. No errors. But when I look in the database it saves an empty string. $_GET['timezones'] is empty. How is that possible? What am I doing wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's an emtry string, because you are sending an empty string. Look at this line you posted:

$.getScript('/updateTimeZone.php?timezones=');

You probably forgot to give the timezone you wanted into there like this:

$.getScript('/updateTimeZone.php?timezones=THE_TIMEZONE');

Replace THE_TIMEZONE with the timezone you want to set...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...