I have number of links that open bootstrap modal popup:
Edit 15
Edit 32
the problem - when the modal open it should get the link parameters:
data-act="edit" data-itinID="5" data-secID="15"
Well, it's not happening...
The script in the links page is:
<script>
// send data to modal file
$('#manageSec-model').on('show.bs.modal', function (e) {
var button = $(e.relatedTarget);
var act = button.data('act');
var itinID = button.data('itinid');
var secID = button.data('secid');
var date = button.data('date');
var $modal = $(this);
var info = 'act=' + act + "&itinID=" + itinID + "&secID=" + secID + "&date=" + date;
// alert(info);
$.ajax({
cache: false,
type: 'GET',
url: 'itinPage-secManage.view.php',
data: info,
success: function(data) {
$modal.find('.modal-body').html(data);
setTimeout(function(){ //added this line.
setImageUploader()
})
}
});
});
</script>
Modal:
echo "itinID: ".$_GET['itinID']." secID: ".$_GET['secID'];
Result in Modal:
itinID: secID:
itinID: 5 secID: 15
two lines (not sure why...)
for this to work you will have to call ajax on click of the anchor tag and for passing the values to ajax you can do following on click of anchor tag
$(this).attr("id");
or
$(this).attr("data-secID");//haven't tried this 2nd one
and then launch modal with JavaScript or jQuery with
$("#someId").modal();
Try changing
var button = $(e.relatedTarget);
to
var button = $(e.target);
Related
I have script with multiple buttons which when clicked run a php script via AJAX. I would now like the result to show in the div with the button. I have tried this and parent but neither work.
Example below: when clicked on .showme I want the result to show in the #here div within the same its parent.
$(document).ready(function() {
$('.showme').bind('click', function() {
var id = $(this).attr("id");
var num = $(this).attr("class");
var poststr = "request=" + num + "&moreinfo=" + id;
$.ajax({
url: "../../assets/php/testme.php",
cache: 0,
data: poststr,
success: function(result) {
$(this).getElementById("here").innerHTML = result;
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='request_1 showme' id='rating_1'>More stuff 1
<div id="here"></div>
</div>
<div class='request_2 showme' id='rating_2'>More stuff 2
<div id="here"></div>
</div>
<div class='request_3 showme' id='rating_3'>More stuff 3
<div id="here"></div>
</div>
I think this will do:
$(document).ready(function () {
$('.showme').bind('click', function () {
//keep the element reference in a variable to use in ajax success
var _this = $(this);
var id = $(this).attr("id");
var num = $(this).attr("class");
var poststr = "request=" + num + "&moreinfo=" + id;
$.ajax({
url: "../../assets/php/testme.php",
cache: 0,
data: poststr,
success: function (result) {
//use the element reference you kept in variable before ajax call instead of $(this)
//also use jQuery style, getElementById is undefined if you call after $(this)
//.find() will call it's child in any level, also better you use classes instead of using same id multiple times
_this.find("#here").html(result);
}
});
});
});
I have a button in a page. On clicking the button it should go to another page and that page should be viewed. Also I want to pass some values to the second page when the button is clicked and display the passed values in the second page.
I have written a code in ajax but it is not working.
<script>
$(document).ready(function(){
$(".chk").click(function(){
if($('input.checkin:checked').val()){
var apikey = '60CF3C2oh7D+Q+aHDoHt88aEdfdflIjFZdlmsgApfpvg8GXu+W8qr7bKM33cM3';
var password = 'fHdfvxk';
var endpoint = 1;
var method = 'ProcessPayment';
var dataString = 'APIKey='+apikey+'&APIPassword='+password+'&ddlSandbox='+endpoint+'&ddlMethod='+endpoint;
$.ajax({
type: "POST",
url: "responsive.php",
data: dataString,
cache: false,
success: function(result){
}
});
//window.location.href= 'http://localhost/m/responsive.php';
}
else{
alert("Please Accept the terms and conditions and continue further!!!!");
}
}); });
</script>
I have written a code in ajx when button click, but it will only pass the values to that page. But the page cannot be viewd. Can anyone suggest a solution for this ?
Instead of using ajax you can redirect to the page.
<script>
$(document).ready(function(){
$(".chk").click(function(){
if($('input.checkin:checked').val()){
var apikey = '60CF3C2oh7D+Q+aHDoHt88aEdfdflIjFZdlmsgApfpvg8GXu+W8qr7bKM33cM3';
var password = 'fHdfvxk';
var endpoint = 1;
var method = 'ProcessPayment';
//var dataString = 'APIKey='+apikey+'&APIPassword='+password+'&ddlSandbox='+endpoint+'&ddlMethod='+endpoint;
// use location href instead of ajax
window.location.href = "responsive.php?APIKey='+apikey+'&APIPassword='+password+'&ddlSandbox='+endpoint+'&ddlMethod='+endpoint;
}
else{
alert("Please Accept the terms and conditions and continue further!!!!");
}
});
});
</script>
I have this scenario:
I have a simple php file with only few html elemnts: a div called switch, another called lamp and a couple of buttons.
The two buttons are labeled On and Off.
The lamp div is empty.
The switch div is empty too, but is updated using jQuery and Ajax with the content of a txt file, that only contains one word: it could be On or Off.
What i'm traying to achieve is this: whenever the file is updated with the word On or Off i would like the On or Off button to be triggered correspondingly and the lamp div to change the background color. Is it possible?
UPDATE:
Example:
(function($){
$(document).ready(function() {
$.ajax({
url : "testfile.txt",
dataType: "text",
success : function (data) {
$("#switch").html(data);
// this doesn't seems to work...
var word = data.toLowerCase();
$('#' + word).trigger('click');
// this works
$(document).ajaxStop(function(e){
var response = $("#switch").html();
$("#" + response.toLowerCase()).trigger("click");
});
var $container = $("#switch");
var refreshId = setInterval(function()
{
$container.load('testfile.txt').html();
}, 2000);
}
});
});
})(jQuery);
<div id="switch"></div>
<div id="on" class="button">On</div>
<div id="off" class="button">Off</div>
<div id="lamp"></div>
Since the response is only one word. Why not try
var word = data.toLowerCase();
$('#' + word).trigger('click');
in the success callback.
If you have only one ajax request, you can do like this:
$(document).ajaxStop(function(e){
var response = $("#switch").text();
// do what you want with variable response here
$("#" + response.toLowerCase()).trigger("click");
});
Maybe this can help for what you need:
(function($){
$(document).ready(function() {
var $container = $("#switch");
$container.load("testfile.txt", function() {
setInterval(function() {
$container.load("testfile.txt");
}, 2000);
});
});
})(jQuery);
Use clearInterval() to stop the timer when needed.
So I am basically creating a Restaurant Menu editor for their website. The issue I am having is when the click a category named Brunch, I load the file edit_cat.php via ajax onto the page. All data is passed correctly, but on success of the form being filled out I would like to post a success message on the parent window and am having no luck. Coincidentally, upon success the alert(data) does popup with the response.
edit_cat.php both handles the form submission and is the form
$(document).ready(function(){
$('.editBtn').on('click', function(e) {
e.preventDefault();
var $this = $(this),
id = $this.data('id'),
type = $this.data('type');
if (type == 'cat') {
data = "&cat=" + id;
$.ajax({
data: data,
type: 'POST',
url: 'edit_cat.php',
success: function(data) {
$('#contentLeft').html(data);
}
});
}
});
$('#contentLeft').on('click', 'input[type="submit"]', function(e) {
e.preventDefault();
var $this = $(this),
frm = $('#edit-cat-frm'),
id = $('form').data('id'),
name = $(frm).find('input[name="name"]').val(),
desc = $(frm).find('textarea[name="desc"]').val(),
send = $(frm).find('input[name="submit"]').val();
data = "&cat=" + id + "&name=" + name + "&desc=" + desc + "&submit=" + send;
$.ajax({
data: data,
type: 'POST',
url: 'edit_cat.php',
success: function(data) {
window.parent.$('.left-container-head').innerHtml(data);
}
});
});
});
Can you please try this as simply,
$('.left-container-head').html(data);
Try this:
$(".left-container-head", window.parent.document).html(data);
I have a problem and just can't find where the old values are coming from. What I have is a forum and list of replies where the user has the ability to rate good advice, bad advice on each reply. If you click on one it fires off a java script and the database is updated... the other button hides to show something happened. Where i am running into problems is on a fresh page refresh the first button works as designed but all others are passing not only the next click event values (which the script responds where you have already voted) but is passing ALL the previous clicked values. If I vote on four different posts then all four values post and three showing I have already voted. How can I purge the previous click event values?
<script>
function doGABAbad(forum_post_id,type){
$(".badadviceclick").click(function(){
var element = $(this);
var I = element.attr("id");
var info = 'id=' + I;
$("#gaba_float_right").html('<img src="loader.gif"/>').show();
$.post('updateGABA.php', {forum_post_id: forum_post_id,type: type}, function(data){
if(isNaN(parseFloat(data))){
alert(data);
}else{
$('#'+forum_post_id+'_'+type+'s').text(data);
}
$('#goodadvice'+I).fadeOut(200).show();
});
});
}
</script>
<script>
function doGABAgood(forum_post_id,type){
$(".badadviceclick").click(function(){
var element = $(this);
var I = element.attr("id");
var info = 'id=' + I;
$("#gaba_float_right").html('<img src="loader.gif"/>').show();
$.post('updateGABA.php', {forum_post_id: forum_post_id,type: type}, function(data){
if(isNaN(parseFloat(data))){
alert(data);
}else{
$('#'+forum_post_id+'_'+type+'s').text(data);
}
$('#badadvice'+I).fadeOut(200).show();
});
});
}
</script>
This is where I am building my Div's
<div id="goodadvice'.$forum_post_id.'">
<a id="'.$forum_post_id.'" class="badadviceclick" href="#" onClick="return false" onmousedown="javascript:doGABAgood('.$forum_post_id.',\'goodadvice\');">Good Advice '.$good_advice.'</a>
</div>
<div id="badadvice'.$forum_post_id.'">
<a id="'.$forum_post_id.'" class="badadviceclick" href="#" onClick="return false" onmousedown="javascript:doGABAbad('.$forum_post_id.',\'badadvice\');">Bad Advice '.$bad_advice.'</a>
</div>
The reason for that is you attach events in both javascript and jquery (jquery based event in javascript based event). you need to use one or another.
<script>
function doGABAbad(forum_post_id,type){
var element = $(this);
var I = element.attr("id");
var info = 'id=' + I;
$("#gaba_float_right").html('<img src="loader.gif"/>').show();
$.post('updateGABA.php', {forum_post_id: forum_post_id,type: type}, function(data){
if(isNaN(parseFloat(data))){
alert(data);
}else{
$('#'+forum_post_id+'_'+type+'s').text(data);
}
$('#goodadvice'+I).fadeOut(200).show();
});
}
function doGABAgood(forum_post_id,type){
var element = $(this);
var I = element.attr("id");
var info = 'id=' + I;
$("#gaba_float_right").html('<img src="loader.gif"/>').show();
$.post('updateGABA.php', {forum_post_id: forum_post_id,type: type}, function(data){
if(isNaN(parseFloat(data))){
alert(data);
}else{
$('#'+forum_post_id+'_'+type+'s').text(data);
}
$('#badadvice'+I).fadeOut(200).show();
});
}
</script>
First modify the HTML like so:
<div id="goodadvice'.$forum_post_id.'">
<a id="'.$forum_post_id.'" class="goodadviceclick" href="javascript:void(0);">Good Advice '.$good_advice.'</a>
</div>
<div id="badadvice'.$forum_post_id.'">
<a id="'.$forum_post_id.'" class="badadviceclick" href="javascript:void(0);">Bad Advice'.$bad_advice.'</a>
</div>
Next, you can refactor the functions like so:
function doGABA(e) {
e.preventDefault();
var element = $(this);
var forum_post_id = element.attr("id");
var type = element.hasClass('goodadviceclick') ? 'good' : 'bad';
var info = 'id=' + I;
$("#gaba_float_right").html('<img src="loader.gif"/>').show();
$.post('updateGABA.php', {forum_post_id: forum_post_id, type: type + 'advice'}, function(data){
if(isNaN(parseFloat(data))){
alert(data);
}else{
$('#'+forum_post_id+'_'+type+'s').text(data);
}
$('#' + type + 'advice'+I).fadeOut(200).show();
});
}
Then remove the onmousedown attributes on your anchor tags, and do it in jQuery:
$('.goodaviceclick, .badadviceclick').click(doGABA);