I have a Post Form in wich i use to Search results.
<form method="post" enctype="multipart/form-data" name="byMonthYear">
<label><h2>Search Colection by Month and Year:</h2></label>
<select name="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="year">
<?php
$get_year = date('Y') + 1;
for($i = $get_year;$i >= 2013;$i--){
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
<input type="button" value="Search" onclick="return search_buss_byMonthYear()">
</form>
On click i call AJAX to get the results search_buss_byMonthYear();
function search_buss_byMonthYear(){
$('#loading').show();
var month = document.forms['byMonthYear']['month'].value;
var year = document.forms['byMonthYear']['year'].value;
var dataString = 'month='+ month + '&year=' + year;
if(month == '')
{
document.getElementById("results").innerHTML = "<div class='alert_error'>You must fill all fields! <br></div>";
}else{
$.ajax({
type: "post",
url: "inc/byMonthYear.php",
data: dataString,
contentType: "application/x-www-form-urlencoded",
success: function(responseData, textStatus, jqXHR) {
$('#loading').hide();
document.getElementById("results").innerHTML = responseData;
},
error: function(jqXHR, textStatus, errorThrown) {
$('#loading').hide();
document.getElementById("results").innerHTML = "<div class='alert_error'>Your action had errors! <br></div>";
}
});
}
}
on the File byMonthYear.php i have the php script to get the results, and is working very good, BUT i want to add some additional javascript action on that page byMonthYear.php.. But its not responding the jQuery there! I put just alert("hello"); to test is but its not responding !! Any idea how to bind the jQuery to work in this conditions !
Thanks
Solved: I just added this on success and javascript responds.
success: function(responseData, textStatus, jqXHR) {
$('#results').html( responseData );
},
Thanks for answers.
The Javascript you added does not work in byMonthYear.php. You are trying to call a php webpage by ajax and that page will be executed server side not client side.
You can try to return the Javascript code by echo
and a flag. If that flag is set then display the Alert()
. Use JSON to send data.
Guess you understood.
i am not a hundred percent sure but try including your javascript file to the new php page it souds like a problem i had a wile back where i was using ajax to call load a page but the javascript did not work so i had to include them again like so
<head>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="myjava.js"></script>
</head>