I want to make facebook like button.when i click like.undefined $ is appearing in console.it should echo 22 value default value on click.
function like_add(article_id) {
$.post('ajax/like_add.php', {article_id:article_id}, function(data){
if(data == 'success')
{
like_get(article_id);
}
else
{
alert(data);
}
});
}
function like_get(article_id) {
$.post('ajax/like_get.php',{article_id:article_id}, function(data){
$('#article_'+article_id+'_likes').text(data);
});
}
foreach($articles as $article){
echo '<li>',$article['article_title'],'</p><p><a class="like" href="#"
onclick="like_add(', $article['article_id'] ,');">Like</a>
<span id="article_', $article['article_id'] ,'_like">', $art
jQuery is not included in current page.
You can include it with this code:
<script src="https://code.jquery.com/jquery-2.2.1.min.js"></script>
Place it between <body> </body> before your code.
But also you can load it async way:
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = "https://code.jquery.com/jquery-2.2.1.min.js";
script.onreadystatechange = handler;
script.onload = handler;
head.appendChild(script);
function handler() { console.log("jQuery loaded!"); }
handler() will be called when jQuery will be loaded.
Related
I have function validate my form and after form submitted
else
{
$('.submit-button').val('Wait please...');
$('.submit-button').attr('disabled', 'disabled');
return true;
}
PHP redirect to main page
function wpcallback_get_target() {
global $wpcallback_plugin_option;
if($value = $callback_plugin_option['target'])
return get_permalink($value);
return get_site_url();
}
PHP get site url then how I can make thanks modal window opened?
I tried with .modal but can't find right place for it.
$('#myModal').modal('show');
place $('#myModal').modal('show'); in the bottom of you view file or you can add following code in head tag
$(document).ready(function(){
$('#myModal').modal('show');
});
to prevent model every time on page load, update your PHP file:
function wpcallback_get_target() {
global $wpcallback_plugin_option;
if($value = $callback_plugin_option['target'])
return get_permalink($value);
$url = get_site_url();
return $url."?response=true";
}
in view file:
<?php if(isset($_GET['response']) && $_GET['response'] == 'true'){ ?>
$(document).ready(function(){
$('#myModal').modal('show');
});
<?php } ?>
use Javascript code:
$(document).ready(function(){
var myURL = window.location;
var res = myURL.search("response=true");
if(res > 0){
$('#myModal').modal('show');
}
});
Try this on your php.
echo "<script>
$(window).load(function(){
$('#yourthanksmodel').modal('show');
});
</script>";
I have this AJAX GET:
function edit(str){
ajax.onreadystatechange=function()
{
if (ajax.readyState==4 && ajax.status==200)
{
document.getElementById("editaircraftdialog").innerHTML=ajax.responseText;
$("#editaircraftdialog").dialog('open');
$("#loadingdialog").dialog('close');
}
}
ajax.open("GET","./edit_aircraft.php?icao="+str,true);
ajax.send();
$("#loadingdialog").dialog('open');
}
The JQuery code in edit_aircraft.php does not work. Here's an example:
<script>
$(function() {
$("#insertaircraft")
.button()
.click(function(event) {
});
});
</script>
I have had the same problem in the past and I cannot fix it.
You can not load JavaScript with innerHTML. It does not get evaluated.
Use jQuery to your advantage
function edit(str){
var loading = $("#loadingdialog").dialog('open');
var aircraft = $("#editaircraftdialog");
aircraft.load("./edit_aircraft.php?icao="+str, function(){
loading.dialog('close');
aircraft.dialog('open');
});
}
I have a requirement to show an Exit Popup on one of our processing pages. I am showing the exit popup by registering a client side javascript like
window.onbeforeunload = ShowExitPopUp();
The popup executes fine if you close the window, or try to type in a different URL. However the issue is that my processing page is also performing a "Response.Redirect" on the server side once the process completes. When response.redirect happens the exitpopup also shows up. Is there a way to have the exit popup not show up in that case?
this is the code below which i am using
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.Event.subscribe('comment.create',
function (response) {
window.location = "http://domain.com";
});
FB.Event.subscribe('comments.remove',
function (response) {
window.location = "http://domain.com";
});
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//]]>
</script>
<script type="text/javascript">
var ShowExitPopup = true;
function ExitPage()
{
if (ShowExitPopup)
{
ShowExitPopup = false;
location.href = "http://www.YOURURL.com/destination";
return '****************************************\n\YOUR HEADLINE\n\n YOUR TEXT1 \n\n YOUR TEXT "\n\n | |\n | |\n V V\n 96+ v\n ********************************************************\n';
}
}
</script>
if (document.getElementById('<%=Panel.ClientID %>').style.display == "") {
$find("<%= Popup.ClientID %>").hide();
document.getElementById("<%= btncloseAcc.ClientID %>").click();
}
try this..........
I am using this code in php or html file for redirect
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
<script language="JavaScript">
var country= geoip_country_code();
if(country == "US" )
{
<!--
window.location = "http://google.com"
//-->
}
</script>
but i want to use a js file which do the same function but its extension should be .js
as http://domain.com/redirect.js so what would be the code?
This includes a script include function with a callback, so that the Maxmind client code won't run until the Maxmind library has been loaded.
loadScript("http://j.maxmind.com/app/geoip.js", function() {
var country = geoip_country_code();
if (country === "US") {
window.location = "http://google.com/";
}
});
function loadScript(url, callback) {
// adding the script tag to the head as suggested before
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
// then bind the event to the callback function
// there are several events for cross browser compatibility
script.onreadystatechange = callback;
script.onload = callback;
// fire the loading
head.appendChild(script);
}
I using PHP/Javascript - Widget of alexmarandon from link http://alexmarandon.com/articles/web_widget_jquery/
And in project of me is:
script.js
html.php
demo.html
In script i using code:
(function() {
// Localize jQuery variable
var jQuery;
/******** Load jQuery if not present *********/
if (window.jQuery === undefined || window.jQuery.fn.jquery !== '1.7.1') {
var script_tag = document.createElement('script');
script_tag.setAttribute("type","text/javascript");
script_tag.setAttribute("src",
"https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js");
if (script_tag.readyState) {
script_tag.onreadystatechange = function () { // For old versions of IE
if (this.readyState == 'complete' || this.readyState == 'loaded') {
scriptLoadHandler();
}
};
} else {
script_tag.onload = scriptLoadHandler;
}
// Try to find the head, otherwise default to the documentElement
(document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
} else {
// The jQuery version on the window is the one we want to use
jQuery = window.jQuery;
main();
}
/******** Called once jQuery has loaded ******/
function scriptLoadHandler() {
// Restore $ and window.jQuery to their previous values and store the
// new jQuery in our local jQuery variable
jQuery = window.jQuery.noConflict(true);
// Call our main function
main();
}
/******** Our main function ********/
function main() {
jQuery(document).ready(function($) {
/******* Load CSS *******/
var css_link = $("<link>", {
rel: "stylesheet",
type: "text/css",
href: "style.css"
});
css_link.appendTo('head');
/******* Load HTML *******/
var jsonp_url = "data.php?callback=?";
$.getJSON(jsonp_url, function(data) {
$('#example-widget-container').html(data);
});
$('.submit').click(function(){
alert('test');
});
});
}
})(); // We call our anonymous function immediately
Then i call data in data.php
$str = '<div class="widget_advance">';
$str .= '<form method="post" id="form_widget_advance">';
$str .= '<input type="submit" value="Tìm" class="submit" />';
$str .= '</form>';
$str .= '</div>';
echo $_GET['callback'] . '(' . json_encode($str) . ');';
finally, in demo.html is result:
<script src="script.js" type="text/javascript"></script>
<div id="example-widget-container"></div>
=> When I click on button submit is result not show alert('test'); How to fit it ?
Put this inside as such:
$.getJSON(jsonp_url, function(data) {
$('#example-widget-container').html(data);
$('.submit').click(function(){
alert('test');
});
});
You see, it has to be inside the callback. You can't bind to the submit button if it's not in the DOM yet. You could also do something along the lines of: $("#someForm").submit(function() { ... });