Ajax Function

Hi,
Ajax function display a main page of index.php inside

. This is the code I wrote in php.

[php]// php code
if ($_POST) {
require(‘db.php’);
$district = $_POST[‘district’];
if ($country != ‘’) {
$sql1 = “SELECT * FROM zone WHERE districtid=” . $district;
$result1 = mysqli_query($con, $sql1);
echo “”;
echo “Select”;
while ($row = mysqli_fetch_array($result1)) {
echo “<option value=’” . $row[‘zone_id’] . “’>” . $row[‘zone’] . “”;
}
echo “”;
} else {
echo ‘’;
}
}

// At index.php main page
while ($row = mysqli_fetch_array($resultdistrict)) {
echo “<option selected=‘selected’ value=’” . $row[‘districtid’] . “’>” . $row[‘districtname’] . “”;
}

select
.

// This is Ajax
function change_zone() { // Call to ajax function
var country = $(’#district’).val();
var dataString = “district=” + district;
$.ajax({
type: “POST”,
url: “index.php”, // Name of the php files
data: dataString,
success: function (html)
{
$("#get_zone").html(html);
}
}); // END OF AJAX FUNCTION:
}[/php]

How this happen and please advice how to avoid it happen.

Thanks

First of all you can’t have more than one echo statement if you are using Ajax and I believe you are looking at this backwards. Though I’m going to have to look at you code better and maybe in the meantime someone else will help you further.

He doesn’t use json, he’s only fetching some html with ajax which should work fine with multiple edits.

OP: what doesn’t work? Do you get any errors?

OP, Look up the Syntax of a an HTML Select and then look at what you did. See a problem there?

Hello Everybody,

The website page is working good now. Solved this topic by removed some echo lines and put an Ajax function on another page.
Thanks a lot for your advice guys.

Sponsor our Newsletter | Privacy Policy | Terms of Service