I originally coded this piece to bring back a single data point. I realized I needed more fields returned with an onchange event (drop down select) and changed it to use JSON. It is not returning any data. The drop down is built dynamically through PHP when the page is first loaded. I'm new to this, so any help would be much appreciated.
Dropdown Code:
<p id="dropdown" style="DISPLAY: none" >
<?php
$query = "call test.spsMSTR_AllCatListBuild";
$stmt = $conn->query( $query );
$dropdown = "<select id='catlist' name='catlist' onchange='getval(this);'>";
$dropdown .= "\r\n<option value= 'NA'>Select Category</option>";
foreach ($stmt as $row) {
$dropdown .= "\r\n<option value='{$row['ID']}'>{$row['RPT_NAME']}</option>";
}
$dropdown .= "\r\n</select>";
echo $dropdown;
$conn = null;
?>
</p>
Ajax/JSON code:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script id="source" language="javascript" type="text/javascript">
$(document).ready(function(){
$("#catlist").change(function(){
var vid = document.getElementById("catlist").value;
$.getjson("ajax.php",
{catid:vid},
function(result){
alert(result); }
.error(function(xhr) {
alert(xhr)
})
; )
})})
</script>
PHP Code:
<?php include('./DBConfig.php'); ?>
<?php
$vid = $_GET["catid"];
$query = "SELECT RPT_NAME, ACTIVE FROM test.MSTR_REPORT_MASTER WHERE ID = $vid" ;
$stmt = $conn->query( $query );
//$result = $stmt->fetchColumn();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode($result);
?>
So, I have corrected your errors and you should have the below for it to work with no errors, unless there is something else that is causing errors.
<select id='catlist' name='catlist'>
<option value='NA'>Select Category</option>
<option value='id1'>val1</option>
<option value='id2'>val2</option>
<option value='id3'>val3</option>
</select>
$(function(){
$("#catlist").change(function() {
var sVal = $(this).val();
if (sVal !== "NA") { // I am assuming you don't want to make an ajax call when the value is 'NA'!
$.getJSON("ajax.php", {catid: $(this).val()}, function(result) {
alert(result);
});
//by the way $(this).val() = id1|id2|id3
}
});
});
Well if you format your code, you can see your problem.
$(document).ready(function() {
$("#catlist").change(function() {
var vid = document.getElementById("catlist").value;
$.getjson("ajax.php", {
catid: vid
},
function(result) {
alert(result);
}
.error(function(xhr) { //<-- error inside getJSON
alert(xhr)
});) //<-- a random )
})
})
and
You have an inline event onchange='getval(this);' but you do not have a function getval listed.
Related
I am trying to set up a select box that would show up the cities depending on the prior selection of the state.
Basically, I am using ajax to run my php.file to populate my <option>. In the php file I successfully passed the pre-selected state to query the database. However, now, to populate the <option> I am using ajax success to call the php file, however, whenever I try to pass the variable containing the php code it shows up commented with !-- and --.
// hmtl
<select id="select-city" required >
<option disabled selected>Selecione sua Cidade</option>
</select>
// js code
function fillSelectCity () {
var getState = document.getElementById('selectState');
var stateID = getState.options[getState.selectedIndex].value;
$.ajax ({
type: "POST",
url: "fillcity.php",
data: { stateID : stateID },
success: function (){
var phpfile = "'fillcity.php'"
var tag = "<?php include_once " + phpfile + " ?>";
$('#select-city').html(tag);
/// here the output is "<!-- ?php include_once 'fillcity.php' ? -->"
}
})
}
//php file
<?php
$conn = mysqli_connect("host", "user", "pass", "db");
if(isset($_POST['stateID']))
{
$stateID = $_POST['stateID'];
}
$query = "SELECT * FROM states WHERE stateID = '$stateID'";
$result_one = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result_one); //my table has a specific ID for each state, so I am fetching the acronoym of the state according to the id;
$stateUf = $row['uf']; // passing the acronym to the $stateUf
mysqli_free_result($result_one);
$queryCity = "SELECT * FROM city WHERE Uf = '$stateUf'"; //query all cities with the acronym
if ($result = mysqli_query($conn, $queryCity)){
while ($row = mysqli_fetch_assoc($result)){
$id = $row['cityID'];
$name = $row['cityName'];
$name = utf8_encode($name);
echo <<< EOT
"<option value="$id">$name</option>"
EOT;
}
mysqli_free_result($result);}
else {echo "<option>Error</option>";}
?>
I expect to populate my select options by looping through the table city in the php file. The tag <?php include_once 'fillcity.php' ?> was used to populate the state select. Probably, there may be a more direct way to populate accordingly, but as I am new to programming, I am trying to figure things out on my own. But please, feel free to recommend other methods as I am not sure if what I am planning to do will gonna work. Thanks!
You can try this one. You can modify it later for improvement.
read.php
<?php
//include header
header('Content-Type: application/json');
$conn= mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$type = $_GET["type"];
if($type == "GetState"){
//SAMPLE QUERY
$sql = "SELECT StateID,StateName from State";
$data = array();
$results = $db -> query($sql);
while($row = mysqli_fetch_assoc($results)){
$data[] = $row;
}
echo json_encode($data);
}
if($type == "GetCity"){
$StateID= $_POST["StateID"];
//SAMPLE QUERY
//LET'S ASSUME THAT YOU HAVE FOREIGN KEY
$sql = "SELECT CityID,CityName from City where StateID = '".$StateID."'";
$data = array();
$results = $db -> query($sql);
while($row = mysqli_fetch_assoc($results)){
$data[] = $row;
}
echo json_encode($data);
}
?>
index.html
<select id="state"></select>
<select id="city"></select>
<!--PLEASE INCLUDE JQUERY RIGHT HERE E.G. <script src='jquery.min.js'></script>-->
<!--DOWNLOAD JQUERY HERE https://jquery.com/-->
<script>
LoadState();
function LoadState(){
$.ajax({
url:"read.php?type=GetState",
type:"GET",
success:function(data){
var options = "<option selected disabled value="">Select
State</option>";
for(var i in data){
options += "<option value='"+data[i].StateID+"'>" + data[i].StateName+ "</option>";
}
$("#state").html(options);
}
});
}
function LoadCity(StateID){
$.ajax({
url:"read.php?type=GetCity",
type:"POST",
data:{
StateID: StateID
},
success:function(data){
var options = "<option selected disabled value="">Select City</option>";
for(var i in data){
options += "<option value='"+data[i].CityID+"'>" + data[i].CityName+ "</option>";
}
$("#city").html(options);
}
});
}
$("#city").change(function(){
LoadCity(this.value);
});
You don't need to include 'fillcity.php. The AJAX call runs that script, and the response is the output. It will be in the parameter of the success function.
function fillSelectCity () {
var getState = $("#selectState").val();
$.ajax ({
type: "POST",
url: "fillcity.php",
data: { stateID : stateID },
success: function (tag){
$('#select-city').html(tag);
}
});
}
I have some code where I need to update a column of a table (MySQL) calling another php file without leaving the page where some tables might allow inline editing.
I have a point in the php echoing of the page, where an icon can be clicked to save input. The code at that point is:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<?php
$sql = "SELECT * FROM table WHERE a_column='certain_value'";
if (mysqli_query($conn, $sql)) {
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$note = $row["note"];
$code = $row["code"];
}
}
}
// some tabled elements not relevant for the issue
echo "<input type='text' id='note_1' name='note_1' value=$note readonly>";
echo "<input type='text' id='new_note' name='new_note'>";
echo "<img src='icon_to_click.png' id='icon_to_click' name='icon_to_click' >";
?>
<script type="text/javascript">
$(document).ready(function() {
$('#icon_to_click').click(function() {
var note_orig = document.getElementById('note_1').value;
var code_val = '<?php echo "$code" ?>';
var note_new = document.getElementById('new_note').value;
if (note_new != note_orig) {
$.ajax({
type: 'POST',
url: 'update_notes.php',
data: {'code': code_val, 'note': note_new},
success: function(response){
document.getElementById('note_1').value = note_new;
}
});
}
});
});
The relevant code of update_notes.php is:
<?php
// connection
$unsafe_note = $_POST["note"];
$code = $_POST["code"];
require "safetize.php"; // the user input is made safe
$note = $safetized_note; // get the output of safetize.php
$sqlupdate = "UPDATE table SET note='$note' WHERE code='$code'";
if (mysqli_query($conn, $sqlupdate)) {
echo "Note updated";
} else {
echo "Problem in updating";
}
// close connection
?>
Now when I run the code and look at the tool, it gives me the error: Uncaught ReferenceError: $ is not defined, linking the error to this line of the previous js code:
$(document).ready(function() {
So, how can I fix that?
It means that you tried to use Jquery in your Javascript Code without calling Jquery Library or the code is called without the library was fully loaded.
I notice :
That you haven't closed your script tag
You use Jquery so you can use $('#id_name') to select element by Id instead of document.getElementById('note_1')
Get element value by using Element.val() instead of Element.value
Try to edit your code like this
<?php
$sql = "SELECT * FROM table WHERE a_column='certain_value'";
if (mysqli_query($conn, $sql)) {
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
$note = $row["note"];
$code = $row["code"];
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Some title</title>
</head>
<body>
<form method="post" accept-charset="UTF-8">
<input type='text' id='note_1' name='note_1' value=<?= $code ?> readonly>";
<input type='text' id='new_note' name='new_note'>";
<img src='icon_to_click.png' id='icon_to_click' name='icon_to_click' >";
</form>
<script>
$(document).ready(function() {
$('#icon_to_click').click(function() {
var note_orig = $('#note_1').val();
var code_val = '<?= $code ?>';
var note_new = $('#new_note').val();
if (note_new != note_orig) {
$.ajax({
type: 'POST',
url: 'update_notes.php',
data: {'code': code_val, 'note': note_new},
success: function(response){
$('#note_1').val() = note_new;
}
});
}
});
});
</script>
</body>
</html>
Hey I have faced same error a day before,this is because you have missed using a jquery library script that is needed. please try using some Updated Jquery CDN . :) It will definitely help
OR
include the jquery.js file before any jquery plugin files.
I have two javascripts function which use to pass two different variable.first javascript is to pass the area in the dropdown and the second one is to pass the name in second dropdown.Now i want to do it within one button submit.Below is my code,which is works partially.When i pass the value to php it's run thru two or three times to get results,and come out with wrong results.Does it any wrong with my ajax or sql query?
$(function() {
$('#form').submit(function(e) {
e.preventDefault();
var id=$(".area").val();
var dataString = 'id='+ id;
$.ajax({
type : 'POST',
url : 'LeaveRecord1.php',
data : dataString,
})
.done(function(data) {
$('.results').html(data);
})
});
});
$(function() {
$('#form').submit(function(e) {
e.preventDefault();
var idd=$(".slct2").val();
var dataStringg = 'idd='+ idd;
$.ajax({
type : 'POST',
url : 'LeaveRecord1.php',
data : dataStringg,
})
.done(function(data) {
$('.results').html(data);
})
});
});
<td><input type="submit" name="report" class="report" id="report" onClick=" myFunction();"></td>
PHP file to capture the value
$poarr =Array();
if (isset($_POST['id'])) {
$sarea=$_POST['id'];
$sql = "SELECT tblLeaveHeader.RefNo, tblLeaveHeader.StaffId, tblLeaveHeader.Branch, tblLeaveHeader.Remark, tblLeaveHeader.Createby, tblLeaveHeader.Approvedd, tblLeaveHeader.Approveby, tblLeaveHeader.AreaCode
FROM tblLeaveHeader INNER JOIN tblStaff ON tblLeaveHeader.AreaCode = tblStaff.AreaCode AND tblLeaveHeader.StaffId = tblStaff.StaffId WHERE (tblLeaveHeader.AreaCode = '$sarea')";
};
if (isset($_POST['idd'])) {
$suser=strtoupper($_POST['idd']);
$sql = "SELECT tblLeaveHeader.RefNo, tblLeaveHeader.StaffId, tblLeaveHeader.Branch, tblLeaveHeader.AreaCode, tblLeaveHeader.Remark, tblLeaveHeader.Createdd, tblLeaveHeader.Createby,
tblStaff.StaffName FROM tblLeaveHeader INNER JOIN tblStaff ON tblLeaveHeader.StaffId = tblStaff.StaffId AND tblLeaveHeader.AreaCode = tblStaff.AreaCode WHERE (tblStaff.StaffName = '$suser')";
};
$link = odbc_connect(DB_HSATTEND, DB_USER, DB_PASS);
$res = odbc_exec($link,$sql);
while ($row = odbc_fetch_array($res)) {
$poarr[] = $row;
}
odbc_free_result($res);
odbc_close($link);
Here is my version. From what I understood from your explanations, the following principle should apply:
If no combobox value selected, then show alert: "Please choose a value".
...else if only area is selected in combobox ".areas", then post only the selected area value.
else (e.g. if name selected in combobox ".names"), then post only the selected name value.
If you really meant something else, then please think about it and reedit your question with a better explanation.
Please read all codes carefully, because I applied names and ids which I found better. Also notice that I used return false in ajax, and no preventDefault() anymore. Also, your database code lacks of two essential elements:
prepared statements - to avoid MySQL injection.
exception handling - to catch all exceptions which might be raised along your PHP codes.
See THIS for a full example of prepared statements + exception handling (using mysqli). You really don't want to continue programming without them ;-)
index.php (with the form):
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Test</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" type="text/javascript" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<script src="index.js" type="text/javascript"></script>
</head>
<body>
<form id="form" name="form" action="" method="post">
<select id="area" name="area" class="area">
<option value="">- Select area -</option>
<option value="123">Area 1</option>
<option value="456">Area 2</option>
<option value="789">Area 3</option>
</select>
<select id="slct2" name="slct2" class="slct2">
<option value="">- Select name -</option>
<option value="John">John</option>
<option value="Smith">Smith</option>
<option value="Mikaela">Mikaela</option>
</select>
<input type="submit" name="report" class="report" id="report">
</form>
<br/><br/>
<div class="results">
Here comes the results...
</div>
</body>
</html>
index.js (with the ajax):
$(document).ready(function () {
$('#form').submit(function (e) {
var areaCode = $(".area").val();
var staffName = $(".slct2").val();
var data = {};
if (areaCode === '' && staffName === '') {
alert('Please choose a value from selects!');
return false;
} else if (areaCode !== '' && staffName === '') {
data.areaCode = areaCode;
} else {
data.staffName = staffName;
}
var ajax = $.ajax({
method: 'post',
dataType: 'html',
url: 'LeaveRecord1.php',
data: data
});
ajax.done(function (response, textStatus, jqXHR) {
$('.results').html(response);
});
ajax.fail(function (jqXHR, textStatus, errorThrown) {
$('.results').html(textStatus + '<br />' + errorThrown);
});
ajax.always(function (response, textStatus, jqXHR) {
//...
});
return false;
});
});
LeaveRecord1.php (where the form values are processed):
<?php
$poarr = array();
if (isset($_POST['areaCode'])) {
$areaCode = $_POST['areaCode'];
$sql = "SELECT
tblLeaveHeader.RefNo,
tblLeaveHeader.StaffId,
tblLeaveHeader.Branch,
tblLeaveHeader.Remark,
tblLeaveHeader.Createby,
tblLeaveHeader.Approvedd,
tblLeaveHeader.Approveby,
tblLeaveHeader.AreaCode
FROM tblLeaveHeader
INNER JOIN tblStaff ON
tblLeaveHeader.AreaCode = tblStaff.AreaCode
AND tblLeaveHeader.StaffId = tblStaff.StaffId
WHERE tblLeaveHeader.AreaCode = '" . $areaCode . "'";
} elseif (isset($_POST['staffName'])) {
$staffName = strtoupper($_POST['staffName']);
$sql = "SELECT
tblLeaveHeader.RefNo,
tblLeaveHeader.StaffId,
tblLeaveHeader.Branch,
tblLeaveHeader.AreaCode,
tblLeaveHeader.Remark,
tblLeaveHeader.Createdd,
tblLeaveHeader.Createby,
tblStaff.StaffName
FROM tblLeaveHeader
INNER JOIN tblStaff ON
tblLeaveHeader.StaffId = tblStaff.StaffId
AND tblLeaveHeader.AreaCode = tblStaff.AreaCode
WHERE tblStaff.StaffName = '" . $staffName . "'";
}
$link = odbc_connect(DB_HSATTEND, MYSQL_USERNAME, MYSQL_PASSWORD);
while ($res = odbc_exec($link, $sql)) {
do {
while ($row = odbc_fetch_array($res)) {
$poarr[] = $row;
}
odbc_free_result($res);
} while (odbc_next_result($res));
}
odbc_close($link);
if (count($poarr) > 0) {
echo '<pre>' . print_r($poarr, TRUE) . '</pre>';
} else {
echo 'There are some errors somewhere :-(';
}
You can use following ajax but you have to rewrite your php and sql according to this.
$(function() {
$('#form').submit(function(e) {
e.preventDefault();
var id=$(".area").val();
var idd=$(".slct2").val();
var dataString = 'id='+ id+'&idd='+idd;
$.ajax({
type : 'POST',
url : 'LeaveRecord1.php',
data : dataString,
success : function(data) {
$('.results').html(data);
},
});
});
});
And your PHP code should be
<?php
$poarr =Array();
$empty = false;
if (isset($_POST['id'])) {
$sarea=$_POST['id'];
$sql = "SELECT tblLeaveHeader.RefNo, tblLeaveHeader.StaffId, tblLeaveHeader.Branch, tblLeaveHeader.Remark, tblLeaveHeader.Createby, tblLeaveHeader.Approvedd, tblLeaveHeader.Approveby, tblLeaveHeader.AreaCode
FROM tblLeaveHeader INNER JOIN tblStaff ON tblLeaveHeader.AreaCode = tblStaff.AreaCode AND tblLeaveHeader.StaffId = tblStaff.StaffId WHERE (tblLeaveHeader.AreaCode = '$sarea')";
$link = odbc_connect(DB_HSATTEND, DB_USER, DB_PASS);
$res = odbc_exec($link,$sql);
while ($row = odbc_fetch_array($res)) {
$poarr[] = $row;
$empty = true;
}
odbc_free_result($res);
if($empty){
if (isset($_POST['idd'])) {
$suser=strtoupper($_POST['idd']);
$sql = "SELECT tblLeaveHeader.RefNo, tblLeaveHeader.StaffId, tblLeaveHeader.Branch, tblLeaveHeader.AreaCode, tblLeaveHeader.Remark, tblLeaveHeader.Createdd, tblLeaveHeader.Createby, tblStaff.StaffName FROM tblLeaveHeader INNER JOIN tblStaff ON tblLeaveHeader.StaffId = tblStaff.StaffId AND tblLeaveHeader.AreaCode = tblStaff.AreaCode WHERE (tblStaff.StaffName = '$suser')";
$res = odbc_exec($link,$sql);
while ($row = odbc_fetch_array($res)) {
$poarr[] = $row;
}
odbc_free_result($res);
}
}
odbc_close($link);
}
?>
I got a simple ajax live search script that works fine when I type the keyword in my url and visit the php file. But for some reason when I type the keyword in my input field, nothing happens.
What am I doing wrong?
My input field on products.php:
<input type="search" name="keyword" class="producten-icon divider" placeholder="Zoeken..." id="s_search">
And further down the page I got my result div:
<div id="results"></div>
My ajax script:
<script>
$(document).ready(function () {
$("#s_search").on('keyup',function () {
var key = $(this).val();
$.ajax({
url:'includes/fetch_results.php',
type:'GET',
data:'keyword='+key,
beforeSend:function () {
$("#results").slideUp('fast');
},
success:function (data) {
$("#results").html(data);
$("#results").slideDown('fast');
}
});
});
});
</script>
My fetch_results.php:
<?php
include 'connection.php';
$conn = new Connection;
if($_GET['keyword'] && !empty($_GET['keyword']))
{
// Results names
$results = "SELECT `naam` FROM `producten` WHERE `naam` LIKE '%".$_GET['keyword']."%'";
$resultscon = $conn->query($results);
$resultscr = array();
while ($resultscr[] = $resultscon->fetch_assoc());
$eend = #array_map('current', $resultscr);
// echo '<pre>';
// print_r($eend);
// echo '</pre>';
$resultsoverzicht .= '<div style="height:100%;border:10px solid red;">';
foreach($eend as $result){
$resultsoverzicht .= '
<p>'.$result.'</p>';
}
$resultsoverzicht .= '</div>';
echo $resultsoverzicht;
};
?>
When I use the network inspector I don't see anything posted when typing in the input field. Which should be the case with keyup right?
I want to create state/city dependent dropdown in wordpress. This is my js file code
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#state').change(function(){
var $location = $(this).val();
alert($location);
$.ajax({
url:'ajaxurl',
type: 'post',
data: ({action : 'getcity'}),
success: function() {
$("#district").removeAttr("disabled");
$("#district").append(results);
}
});
});
});
</script>
I have created function called getcity in function.php and add hooks and action to that function and add this js file to theme js folder and enque it in function file. I m getting empty alert ?? Anybody has any idea??
add_action('wp_head','ajaxurl');
function ajaxurl() {
?>
<script type="text/javascript">
var ajaxurl = '<?php echo admin_url('admin-ajax.php')."getcity"; ?>';
</script>
this is dropdown code
<p class="half_form half_form_last">
<label for="property_country"><?php _e('State ','wpestate'); ?></label>
<select name="state" id="state" class="select-submit2">
<option value="">Select state</option>
<?php
$result=$wpdb->get_results("select distinct(state) from tblcitylist");
//$wpdb->get_results($query);
foreach($result as $row) {
$state=$row->state;
echo '<option value="">'.$state.'</option>';
}
?>
</select>
</p>
In function.php
function getcity(){
global $wpdb;
if($_POST['state'])
{
$id=$_POST['state'];
$result=$wpdb->get_results("SELECT * FROM tblcitylist WHERE
state='$id'");
//$wpdb->get_results($query);
foreach($result as $row) {
$city_name = $row-
>city_name;
$city_id = $row->city_id;
echo '<option
value="'.$city_id.'">'.$city_name.'</option>';
//echo '<option value="'.'0'.'">'.'New Phase'.'</option>';
}
}
}
add_action("wp_ajax_nopriv_getcity", "getcity");
add_action("wp_ajax_getcity", "getcity");
I have included js file as follows in functions.php
wp_enqueue_script('my_own_js',
get_template_directory_uri().'/js/my_own_js.js',array('jquery'));
I think it's better to post it as an answer. I'd delete the var ajaxurl from the functions.php and use it inside the page. Then I don't see where you pass the location to the ajax. It should look like this:
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#state').on('change', function() {
var location = this.value;
alert(location);
$.ajax({
type: "POST",
url:'<?php echo admin_url('admin-ajax.php'); ?>',
data: ({'action' : 'getcity', 'location' : location }),
success: function(results) {
$("#district").removeAttr("disabled");
$("#district").append(results);
}
});
});
});
</script>
then the Dropdown should look like this
<select id="state">
<option value="state1">state1</option>
<option value="state2">state2</option>
...
</select>
And for the getcity you have to get the right $_POST:
function getcity(){
global $wpdb;
if($_POST['location']){
$id=$_POST['location'];
$result=$wpdb->get_results("SELECT * FROM tblcitylist WHERE state='$id'");
$html = '';
foreach($result as $row) {
$city_name = $row->city_name;
$city_id = $row->city_id;
$html .= '<option value="'.$city_id.'">'.$city_name.'</option>';
}
}
}
add_action("wp_ajax_nopriv_getcity", "getcity");
add_action("wp_ajax_getcity", "getcity");