I would like to display my website ads on other websites like google ads but I got error
Uncaught SyntaxError: Unexpected token < in JSON at position 0
I have used the codeigniter frame work and jquery, it is taking content as variable. Are there any possibilities to solve this issue?
This my Script code:
(window.jQuery || document.write("<script src=\"//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js\"><\/script>"))
(function() {
var x = document.createElement("script");
x.type = "text/javascript";
x.async = true;
x.src = "http" + ("https:" == document.location.protocol ? "s" : "") + "://domain/ads/Ads/demo_ad";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(x, s)
})();
And My PHP code:
function demo_ad()
{
$ad_var = "<a href='http://www.example.com'><div style='position:absolute; width:560px; height:300px; z-index:10000;'><img width='600' height='200' src='http://www.w3schools.com/css/trolltunga.jpg'></div></a>";
echo $ad_var;
}
Here do this:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script type="text/javascript">
(function()
{
var x = document.createElement("script");
x.type = "text/javascript";
x.async = true;
x.src = "http" + ("https:"==document.location.protocol?"s":"") + "://domain/ads/Ads/demo_ad";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(x, s)
})();
</script>
The PHP:
function demo_ad()
{
$ad_var = "<a href='http://www.aqua.deals'><div><img width='600' height='200' src='http://www.w3schools.com/css/trolltunga.jpg'></div></a>";
return $ad_var;
}
call to the funtion like this demo_ad()
Related
Is there any way to convert an iframe with all attributes it contains into a div or php.
<iframe src='left_nav.php' name='left_nav' class="daemon" scrolling="auto" frameborder='0' height='100%' width="100%"></iframe>
If I use the php include function to call the left_nav.php file:
<?php include left_nav.php; ?>
How to load content which was loading in the frame into the div.
In main.title file (other file)
function toencounter(rawdata) {
document.getElementById('EncounterHistory').selectedIndex=0;
if(rawdata=='') {
return false;
} else if (rawdata=='New Encounter') {
top.window.parent.left_nav.loadFrame2('nen1','RBot','forms/newpatient/new.php? autoloaded=1&calenc=')
return true;
} else if (rawdata=='Past Encounter List') {
top.window.parent.left_nav.loadFrame2('pel1','RBot','patient_file/history/encounters.php')
return true;
}
var parts = rawdata.split("~");
var enc = parts[0];
var datestr = parts[1];
var f = top.window.parent.left_nav.document.forms[0];
frame = 'RBot';
if (!f.cb_bot.checked) {
frame = 'RTop';
}
parent.left_nav.setEncounter(datestr, enc, frame);
top.frames[frame].location.href = '../patient_file/encounter/encounter_top.php?set_encounter=' + enc;
}
In left_nav file
setEncounter(edate, eid, frname) {
if (eid == active_encounter) return;
if (!eid) edate = '<?php xl('None','e'); ?>';
var str = '<b>' + edate + '</b>';
setDivContent('current_encounter', str);
active_encounter = eid;
encounter_locked=isEncounterLocked(active_encounter);
reloadEncounter(frname);
syncRadios();
var encounter_block = $(parent.Title.document.getElementById('current_encounter_block'));
var encounter = $(parent.Title.document.getElementById('current_encounter'));
var estr = ' <b>' + edate + ' (' + eid + ')</b>';
encounter.html( estr );
encounter_block.show();
}
function loadCurrentEncounterFromTitle() {
top.restoreSession();
top.frames[ parent.left_nav.getEncounterTargetFrame('enc') ].location='../patient_file/encounter/encounter_top.php';
}
This is a JS script to loadFrame2
function loadFrame2(fname, frame, url) {
var usage = fname.substring(3);
if (active_pid == 0 && usage > '0') {
alert('<?php xl('You must first select or add a visitor.','e') ?>');
return false;
}
if (active_encounter == 0 && usage > '1') {
alert('<?php xl('You must first select or create an encounter.','e') ?>');
return false;
}
if (encounter_locked && usage > '1') {
alert('<?php echo xls('This encounter is locked. No new forms can be added.') ?>');
return false;
}
var f = document.forms[0];
top.restoreSession();
var i = url.indexOf('{PID}');
if (i >= 0) url = url.substring(0,i) + active_pid + url.substring(i+5);
if(f.sel_frame)
{
var fi = f.sel_frame.selectedIndex;
if (fi == 1) frame = 'RTop'; else if (fi == 2) frame = 'RBot';
}
if (!f.cb_bot.checked) frame = 'RTop';
top.frames[frame].location = '<?php echo "$web_root/interface/" ?>' + url;
if (frame == 'RTop') topName = fname;
return false;
}
Since you want to load content of an other file (left_nav.php) into a div rather than into an iframe, you can use multiple ways to do that.
1) JS:
Create a div container which will hold your content:
<div id="left_nav"></div>
Now, you can use jQuery to load the content easily:
onClick="loadContent('path/to/file/left_nav.php')"
This would be your loadContent function:
function loadContent(path){
$("#left_nav").load(path);
}
2) PHP:
You could also use PHP (pass a parameter to the URL you are currently on yourfile.php?m=left_nav). Then you can include the file, with a controller (MVC principle -> if you want to learn more about it):
<?php
if($_GET["m"] == "left_nav")
include("left_nav.php");
?>
EDIT:
It seems like you need a little mix of both. Instead of your iframe you need to insert a div and load the content at the same time:
<div id="left_nav"><?php include("left_nav.php"); ?></div>
This should be equivalent to creating the iframe. Now, when you change the src of the iframe in your JS scripts, instead of using this line:
top.window.parent.left_nav.loadFrame2('pel1','RBot','patient_file/history/encounters.php');
try changing the content of the div as I stated previously at 1), but you should only need the loadContent function.
I would need some advice/assistance here. I'm trying to pass 2 variable to other page from a link using ajax but when i click the link, there is no response. Seem like my ajax is not working, would appreciate if anyone can assist here. Thanks.
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script type="text/javascript" src="js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="productshow.js"></script>
</head>
<body>
<?php
$sql = mysql_query ("SELECT * FROM espaceproduct WHERE email = 'jaychou#hotmail.com' ");
?>
<?php
$result1 = array();
$result2 = array();
$loopCount1 = 0;
$loopCount2 = 0;
while($row = mysql_fetch_array($sql))
{
$result1[] = $row['thumbnail'];
$result2[] = $row['id'];
$_SESSION['thumbnail'] = $result1;
//$url = "profileview.php?email=".$result1[$loopCount1].'&'. "id=".$result2[$loopCount2];
$loopproduct = $result1[$loopCount1];
$loopid = $result2[$loopCount2];
echo"<br/>"."<br/>";
echo '<a href="#" onClick="ajax_post($loopproduct,$loopid)" >'. $_SESSION['thumbnail'][$loopCount1] .'</a>'."<br/>" ;
$loopCount1++;
$loopCount2++;
}
?>
</body>
</html>
This my ajax page
function list_chats(){
var hr = new XMLHttpRequest();
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
document.getElementById("showbox").innerHTML = hr.responseText;
}
}
hr.open("GET", "productshow.php?t=" + Math.random(),true);
hr.send();
}
setInterval(list_chats, 500);
function ajax_post(la,ka){
// Create our XMLHttpRequest object
var hr = new XMLHttpRequest();
// Create some variables we need to send to our PHP file
var url = "espaceproductinsert.php";
var kn = "add="+la+"&csg="+ka;
hr.open("POST", url, true);
// Set content type header information for sending url encoded variables in the request
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// Access the onreadystatechange event for the XMLHttpRequest object
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status1").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(kn); // Actually execute the request
document.getElementById("csg").value = "";
}
This is the page where the variables should be insert
<?php
$add = $_POST['add'];
$csg = $_POST['csg'];
$sql2 = mysql_query ("INSERT INTO espaceproduct ( storename,productname ) VALUES ('$add','$csg') ");
?>
Smiply Try this
function ajax_post(la,ka){
$.post("espaceproductinsert.php", { add:la, csg:ka},
function(data) {
alert(data);
});
}
In page 1 add this script appropriately
<script language="javascript" type="text/javascript">
var httpObject=false;
if(window.XMLHttpRequest){
httpObject = new XMLHttpRequest();
}else if(window.ActiveXObject){
httpObject = new ActiveXObject("Microsoft.XMLHttp");
}
function tranferData(){
var data1= document.getElementById('div1').value;
var data2= document.getElementById('div2').value;
var queryString = "?data1=" + data1;
queryString += "&data2=" + data2;
httpObject.onreadystatechange = function(){
if(httpObject.readyState == 4 && httpObject.status == 200){
var error = document.getElementById('error');
var response = httpObject.responseText;
alert(response);
}
}
httpObject.open("GET", "page2.php"+queryString ,true);
httpObject.send(null);
}
</script>
You send the data using above script and recieve from another page
page 2
<?php
echo $_GET['data1'];
echo $_GET['data2'];
?>
and on the serverside do this
<?php
header('Content-Type: application/json');
echo json_encode($_GET); //for testing replace with array('key'=>$value);
?>
I've done this before but for some reason the parameters are being passed oddly.
I have a javascript function that I've used to pass parameters, I've ran some tests and in the function the variables are correct.
These are just a few snippets of the js that relate to the issue:
var tdes = document.getElementById("taskDescription1").value;
var tnam = document.getElementById("taskName1").value;
var shif = document.getElementById("shift1").value;
var ttyp = document.getElementById("taskType1").value;
var date = document.getElementById("datepicker").value;
var ooc = document.getElementById("ooc1").value;
var dateSplit = date.split('/');
var deadlineDate = "";
for( var i = 0; i < dateSplit.length; i++){
deadlineDate = deadlineDate + dateSplit[i];
}
xmlhttp.open("GET","subTask.php?q="+ encodeURIComponent(tdes) + "&w=" + encodeURIComponent(tnam) +"&e=" +encodeURIComponent(shif) + "&y=" + encodeURIComponent(ttyp) + "&b=" + encodeURIComponent(deadlineDate) + "&u=" + encodeURIComponent(ooc),true);
I ran a web console and this is what is actually getting passed...
http://***************/****/********/subTask.php?taskName1=test+taskname+works&taskDescription1=test+des&shift1=All&ooc1=Open&taskType1=normal&datepicker=06%2F28%2F2013
I'm not sure what's going on in between the xmlhttp.open and the GET method in php. None of these variables are getting passed.
Why not use jQuery - very straightforward format (I prefer POST...):
$(document).ready(function() {
var tdes = $("#taskDescription1").val();
var tnam = $("#taskName1").val();
var shif = $("#shift1").val();
var ttyp = $("#taskType1").val();
var date = $("#datepicker").val();
var ooc = $("#ooc1").val();
var dateSplit = date.split('/');
var deadlineDate = "";
for( var i = 0; i < dateSplit.length; i++){
deadlineDate = deadlineDate + dateSplit[i];
}
$.ajax({
type: "POST",
url: "subTask.php",
data: "q="+ encodeURIComponent(tdes) + "&w=" + encodeURIComponent(tnam) +"&e=" +encodeURIComponent(shif) + "&y=" + encodeURIComponent(ttyp) + "&b=" + encodeURIComponent(deadlineDate) + "&u=" + encodeURIComponent(ooc),true),
success: function(whatigot) {
alert('Server-side response: ' + whatigot);
} //END success fn
}); //END $.ajax
}); //END document.ready()
Notice how easy the success callback function is to write... anything returned by subTask.php will be available within that function, as seen by the alert() example.
Just remember to include the jQuery library in the <head> tags:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>
Also, add this line to the top of your subTask.php file, to see what is happening:
<?php
$q = $_POST["q"];
$w = $_POST["w"];
die("Value of Q is: " .$q. " and value of W is: " .$w);
The values of q= and w= will be returned to you in an alert box so that (at least) you can see what values they contained when received by subTask.php
Following script should help:
function ajaxObj( meth, url )
{
var x = false;
if(window.XMLHttpRequest)
x = new XMLHttpRequest();
else if (window.ActiveXObject)
x = new ActiveXObject("Microsoft.XMLHTTP");
x.open( meth, url, true );
x.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
return x;
}
function ajaxReturn(x){
if(x.readyState == 4 && x.status == 200){
return true;
}
}
var ajax = ajaxObj("POST", "subTask.php");
ajax.onreadystatechange = function() {
if(ajaxReturn(ajax) == true) {
console.log( ajax.responseText )
}
}
ajax.send("u="+tdes+"&e="+tnam+ ...... pass all the other 'n' data );
I am trying to save graphs on server side. i was succeeded up to save one graph. but i am unable to save more than one graph.
here i mentioned 2 graphs but nly one graph is going to save on server.
how it can be ?
my code is
<script type="text/javascript">
var totalCharts = 2;
function exportCharts(exportType)
{
for( var i = 0; i < totalCharts; i++ ) {
var num = i+1;
var id = "chart"+num+"Id";
exportchart(exportType,id);
}
}
function exportchart(exportType,id)
{
var chart = FusionCharts(id);
// Now, we proceed with exporting only if chart has finished rendering.
if (chart.hasRendered() != true)
{
alert("Please wait for the chart to finish rendering, before you can invoke exporting");
return;
}
// call exporting function
chart.exportChart( {exportFormat: exportType} );
}
</script>
<p align="center">
<input type="button" class="button" value="Export as PNG" onclick="exportCharts('PNG')" id="exportButtonPNG" />
</p>
<div >
<div id="average" style="text-align:center">Loading Chart... </div>
<div id="overall" style="text-align:center">Loading Chart... </div>
</div>
<script type="text/javascript" >
// Render the chart (See documentation for explanation of the codes below)
//echo renderChart("FusionCharts/MSColumn3D.swf", "", $strXML3, "average", 1100, 350);
var chart2 = new FusionCharts("FusionCharts/MSColumn3D.swf", "chart1Id", "600", "400", "0", "1");
chart2.setXMLUrl("average.xml");
chart2.render("average");
var chart1 = new FusionCharts("FusionCharts/MSColumn3D.swf", "chart2Id", "600", "400", "0", "1");
chart1.setXMLUrl("overall.xml");
chart1.render("overall");
</script>
<!-- Google Analytics Tracker Code Starts -->
<script type="text/javascript">
// analytics
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost
+ "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
if (typeof(_gat) == "object") {
var pageTracker = _gat._getTracker("UA-215295-3"); pageTracker._initData(); pageTracker._trackPageview();
}
</script>
How i can solve this?
You may need to chain the call to exportChart function of each chart you have.
var totalCharts = 2;
(function () {
var totalExported = 0,
exportType;
window.FC_Exported = function() {
exportchart();
};
window.exportchart = function(exportFormat) {
exportType = exportType || exportFormat || 'jpg';
totalExported++ ;
var chart = FusionCharts("chart" + totalExported + "Id");
if (totalExported > totalCharts) {
return;
}
if (chart.hasRendered() != true) {
alert("Please wait for the chart to finish rendering, before you can invoke exporting");
}
// call exporting function
chart.exportChart( {exportFormat: exportType} );
};
}());
I'm currently working on a website that allows a user to login though Facebook and from that get all of their information to be used on my site.
e.g If they are single or are they interested in women men or both.
I have been looking around on the Facebook Developers side of there site and there is some sample code on there for getting information about what films they like, so I was just wondering if it is possible to change and adapt this to what I need.
Here's some of the code I have found from this page and where it explains it:
http://developers.facebook.com/blog/post/481
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#
appId=YOUR_APP_ID&xfbml=1"></script>
<fb:login-button show-faces="true" width="200" max-rows="1"
perms="user_likes, friends_likes"></fb:login-button>
FB.api('/me/friends', function(response) { });
FB.api(‘/USER_ID/movies’, function(response) { });
FB.api('/'+movieListSorted[i].id, function(response) {
var newDiv = document.createElement("DIV");
newDiv.innerHTML = "<img src='"+response.picture+"'></img><br/>";
if( response.link) {
newDiv.innerHTML+="<a href='"+response.link+"'>"+response.link
+"</a><br/>";
newDiv.innerHTML+='<iframe src="http://www.facebook.com'
+ '/plugins/like.php?'
+ 'href='+response.link+'&layout=standard&'
+ 'show_faces=true&'
+ 'width=450&action=like&colorscheme=light'
+ '&height=80"'
+ 'scrolling="no" frameborder="0" style="border:none;'
+ 'overflow:hidden;'
+ 'width:450px; height:80px;" allowTransparency="true">
+ '</iframe><br/>';
}
document.getElementById(response.id).appendChild(newDiv);
});
<html>
<head>
<title>Test Page</title>
<script>
var movieList = new Array();
var movieListSorted = new Array();
var friendCount = 0;
function showMovies() {
alert(movieList.length);
}
function compareMovies(movieA, movieB) {
if (movieA.name === movieB.name) return 0;
if (movieA.name > movieB.name) return 1;
return -1;
}
function popularMovies(movieA, movieB) {
return movieB.mCount - movieA.mCount;
}
function data_fetch_postproc() {
document.getElementById('test').innerHTML
= "Generating recommendations ... ";
movieList.sort(compareMovies);
// Now we have sorted list, dedupe and count
mCtr = 0;
for (i = 0; i < movieList.length; i++)
{
var count = 0;
movieListSorted[mCtr] = movieList[i];
for ( j = i; j < movieList.length; j++)
{
if ( movieList[i].name === movieList[j].name ) {
count++;
} else {
break;
}
}
i = i+count-1;
movieListSorted[mCtr++].mCount = count;
}
var maxResults = 100;
if( movieListSorted.length < 100) {
maxResults = movieListSorted.length;
}
movieListSorted.sort(popularMovies);
document.getElementById('test').innerHTML = "";
for( i=0; i<maxResults; i++) {
var newDiv = document.createElement("DIV");
newDiv.id = movieListSorted[i].id;
newDiv.innerHTML = movieListSorted[i].name + ' : Likes - '
+ movieListSorted[i].mCount;
document.getElementById("movies").appendChild(newDiv);
FB.api('/'+movieListSorted[i].id, function(response) {
var newDiv = document.createElement("DIV");
newDiv.innerHTML = "<img src='"+response.picture+"'>"
+ "</img><br/>";
if( response.link) {
newDiv.innerHTML+= "<a href='"+response.link+"'>"
+response.link+"</a><br/>";
newDiv.innerHTML+= '<iframe src='
+ '"http://www.facebook.com/plugins/like.php?'
+ 'href='+response.link+'&layout=standard'
+ '&show_faces=true&'
+ 'width=450&action=like&'
+ 'colorscheme=light&height=80"'
+ 'scrolling="no" frameborder="0" style="'
+ 'border:none; overflow:hidden;'
+ 'width:450px; height:80px;"'
+ 'allowTransparency="true"></iframe><br/>';
}
document.getElementById(response.id).appendChild(newDiv);
});
}
}
function get_friend_likes() {
document.getElementById('test').innerHTML = "Requesting "
+ "data from Facebook ... ";
FB.api('/me/friends', function(response) {
friendCount = response.data.length;
for( i=0; i<response.data.length; i++) {
friendId = response.data[i].id;
FB.api('/'+friendId+'/movies', function(response) {
movieList = movieList.concat(response.data);
friendCount--;
document.getElementById('test').innerHTML = friendCount
+ " friends to go ... ";
if(friendCount === 0) { data_fetch_postproc(); };
});
}
});
}
</script>
</head>
<body>
<div id="fb-root"></div>
<div id="login"></div>
<div id="test"></div>
<div id="movies"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'YOUR_APP_ID',
status : true, // check login status
cookie : true, // enable cookies
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.sessionChange', function(response) {
window.location.reload();
});
FB.getLoginStatus(function(response) {
if (response.session) {
// logged in and connected user, someone you know
get_friend_likes();
document.getElementById('login').innerHTML
='Logout<br/>';
} else {
document.getElementById('login').innerHTML
='<fb:login-button show-faces="true" width="200"'
+ ' max-rows="1" perms="user_likes, friends_likes">'
+ '</fb:login-button>';
FB.XFBML.parse();
}
});
</script>
</body>
</html>
Have you checked out the Graph API:
Facebook Graph API
You also have to make sure you have the proper permissions:
Facebook API Permissions
I'd recommend using the PHP SDK to get this information, especially if you're a beginner. You can use their functions then.
You can find the source code for this (and some documentation included) at the following URL:
https://developers.facebook.com/docs/reference/php/
First of all, in order to get anything from the Graph API, you will need to gain the authentication of the user for your application, this is documented here:
https://developers.facebook.com/docs/authentication/
Then, you can get the information that you need about the current user, using an API call. This is documented here:
http://developers.facebook.com/docs/reference/php/facebook-api/
The code of note here is below, I have edited this to provide the currently logged in user's 'interested_in' field as documented here:
try {
$user_profile = $facebook->api('/me?fields=interested_in','GET');
echo "Interested in: " . $user_profile['interested_in'];
} catch(FacebookApiException $e) {
// Failed API call
error_log($e->getType());
error_log($e->getMessage());
}