LinkedIn example code gives SyntaxError - javascript

Trying to follow a linkedin example but their code does not seem to work
When I copy the example code into a HTML page it gets rendered as this
Profile App Example
'); IN.parse(document.getElementById("profile")) }) }
I get this error in firebug
SyntaxError: unterminated string literal
[Break On This Error]
e="IN/FullMemberProfile" data-id="' + result.values[0].id + '">
but I am not seeing it(in the example code it looks like all the quotes match).
Also get this error
TypeError: $.cookie is not a function
[Break On This Error]
...kie('quck-note-current', JSON.stringify({ "Id": id, "Note": note }), { expires: ...
Edit
Here is the full example code they have.
<html>
<head>
<title>Profile App Example</title>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: o1yf9WMdgd8dp_OGkmtXESCOJFostN8N1jI1AFKY2i0kJ1QFNMOs3a6R5qUoBIqF
authorize: true
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5b1.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.7/jquery-ui.min.js"></script>
<script type="text/javascript">
function loadData() {
IN.API.Profile("me")
.result(function(result) {
$("#profile").html('<script type="IN/FullMemberProfile" data-id="' + result.values[0].id + '"></script>');
IN.parse(document.getElementById("profile"))
})
}
</script>
</head>
<body class="yui3-skin-sam yui-skin-sam">
<div id="profile"></div>
<script type="IN/Login" data-onAuth="loadData"></script>
</body>
</html>
Edit 2
I tried using their api key and I used my api key(what is for some reason alot shorter than their example on but that is what it is showing in the app area under api key)

jQuery removes the script tag when using $(string).
This line:
$("#profile").html('<script type="IN/FullMemberProfile" data-id="' + result.values[0].id + '"></script>');
needs to have </script> becoming <\/script>, which is why the error was found just before:
'); IN.parse(document.getElementById("profile")) }) }
Similar discussion: How to get JavaScript script tags inside jQuery .html() function?

Related

Access to restricted URI denied. Firebug

I have 1 HTML Page and 1 js file . I cannot run script in Firebug on Chrome
it shows following Error :
Access to restricted URI denied.
Code is as per tutorial
HTML Page
<!DOCTYPE html >
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery Example </title>
</head>
<body>
<input type="button" value="Hide" id="toggle_messege" />
<p id="messege">
You see this paragraph
</p>
<script type="text/javascript" src="~/js/toggle.js"></script>
<script type="text/javascript" src="~/js/jquery-1.7.1.min.js"></script>
</body>
</html>
js file
$('#toggle_messege').click(function () {
var value = $('#toggle_messege').attr('value');
$('messege').toggle('fast');
if (value == 'Hide') {
$('#toggle_messege').attr('value', 'Show');
}
else if (value == 'Show') {
$('#toggle_messege').attr('value', 'Hide');
}
});
Similar post :
Error: "Access to restricted URI denied"
http://jquery-howto.blogspot.in/2008/12/access-to-restricted-uri-denied-code.html
They suggest it is same domain policy issue and solution is to access file from webserver(localhost)
my url is
http://localhost/WebApplication2/js/
But couldnot solve the issue ..
plz suggest if something missing
You have errors in your code
1.Change the order of file , jquery reference is first
<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="js/toggle.js"></script>
2.You code must be wrapped in $(document).ready() and it should be in <head> block
$(document).ready(function(){
$('#toggle_messege').click(function () {
var value = $('#toggle_messege').attr('value');
$('#messege').toggle('fast'); // You missed # in this line
if (value == 'Hide') {
$('#toggle_messege').attr('value', 'Show');
} else if (value == 'Show') {
$('#toggle_messege').attr('value', 'Hide');
}
});
});
DEMO

Youtube/Google Data API gapi.client undefined?

I am trying to get this example as a spotify app, which i will heavily edit. This should be pretty simple for anyone with real experience in the Youtube Data API. I know there are a few solutions about problems similar to this with the google APIs but all of the solutions seem to be specific to the api...
The specific errors I get right now:
Uncaught TypeError: Cannot read property 'prototype' of undefined cb=gapi.loaded_0:6
index.html: This normally just loads main.js but to complete this example, I just stripped the code off of the youtube data api example for search.
<!doctype html>
<html>
<head>
<title>Search</title>
</head>
<body>
<div id="buttons">
<label> <input id="query" value='cats' type="text"/><button id="search-button" disabled onclick="search()">Search</button></label>
</div>
<div id="search-container">
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
<script src="scripts/auth.js"></script>
<script src="scripts/search.js"></script>
<script src="https://apis.google.com/js/client.js?onload=onLoadCallback"></script>
</body>
</html>
and search.js:
function handleAPILoaded() {
$('#search-button').attr('disabled', false);
}
// Search for a specified string.
function search() {
var q = $('#query').val();
var request = gapi.client.youtube.search.list({
q: q,
part: 'snippet'
});
request.execute(function(response) {
var str = JSON.stringify(response.result);
$('#search-container').html('<pre>' + str + '</pre>');
});
}

javascript: Getting "DOM Exception 9" while creating custom event

I'm using PhoneGap to develop an android app. in the index.html I load a js file like this:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/style.css" />
<link rel="stylesheet" href="styles/loading.css" />
<script src="scripts/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="scripts/cordova-2.5.0.js"></script>
<script type="text/javascript" src="scripts/readImages.js"></script>
<script type="text/javascript">
function onReadImage(event) {
//do something
}
document.addEventListener("onReadImage", onReadImage, false);
</script>
</head>
<body>
<!--
.....
-->
</body>
</html>
readImages.js
// Some codes
window.readImageEvent= document.createEvent("readImageEvent"); // line 4
readImageEvent.initEvent("onWeddingCakesRead", true, true);
//Some functions
readImageEvent.images = data;
document.dispatchEvent(readImageEvent);
but when I check LogCat, I see this error:
Uncaught Error: NOT_SUPPORTED_ERR: DOM Exception 9 at file:///android_asset/www/scripts/readImages.js: 4
Any ideas?
finally I found out the problem.
I changed the below code:
window.readImageEvent= document.createEvent("readImageEvent");
to:
window.readImageEvent= document.createEvent("Event");
Because "readImageEvent" is not a proper event type. This link could be so useful
about this issue.
According to developer.mozilla.org
The createEvent method is deprecated.
I guess, you can try something like this:
var readImageEvent = new CustomEvent(
"onReadImage",
{
detail: {
images: data
},
bubbles: true,
cancelable: true
}
);
document.dispatchEvent(readImageEvent);
More information about usage, compatibility, etc can be found HERE

String.format not a function

I'm using HTML publisher in hope to have a html page with some javascript codes running on hudson. The HTML code is like this:
<html>
<head>
<!--Load the AJAX API-->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../stringformat.js"></script>
<script type="text/javascript">
......
sql=String.format("/.csv? select from table where exchange=`ABC......")
</script>
</head>
However, after a successful build, my html page doesn't show what it suppose to, and as I check the error console, it says
Error: TypeError: String.format is not a function
I have put my stringformat.js into the top folder, as the HTML publisher doesn't seem to allow the file to contain anything other than HTML files.
Can anyone tell me why the String.format is not loaded properly? Thanks!
PS: stringformat.js is the file i got from
http://www.masterdata.se/r/string_format_for_javascript/
The code should be working properly as this piece of code works outside the hudson
try code:
<html>
<head>
<title>String format javascript</title>
<script type="text/javascript">
String.format = function() {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
var _myString = String.format("hi {0}, i'am {1}","everybody", "stackoverflower");
function show(){
alert(_myString);
}
</script>
</head>
<body>
<input type="button" name="btnTest" id="btnTest" value="Test string format" onclick="show();" />
</body>
</html>

javascript fails to execute mapquest api

I would like for this code to alert the users with their perspective addresses, but for some reason it's not executing. Can someone point me on the right direction?
Thanks!
<html>
<head>
<title>geoload</title>
<script type="text/javascript" src="http://www.mapquestapi.com/geocoding/v1/reverse?key=MY_DEV KEY GOES HERE=40.0755&lng=-76.329999&output=json&callback=renderGeocode"></script>
<script type="text/javascript">
function renderGeocode(response){
var location = response.results[0].locations[0];
alert(location.adminArea5 + ", " + location.adminArea4);
}
</script>
</head>
<body onload=(load"renderGeocode")></body>
</html>
You've missed a + sign:
alert(location.adminArea5 + ", " + location.adminArea4);
^
The body onload is not required, as the call to the mapquestapi includes a callback parameter. The callback parameter is renderGeocode which will call the javascript function of the same name. See code below:
<html>
<head>
<title>geoload</title>
<script type="text/javascript" >
function renderGeocode(response) {
console.log(response)
}
</script>
<script type="text/javascript" src="http://www.mapquestapi.com/geocoding/v1/reverse?key=MY_DEV KEY GOES HERE&lat=40.0755&lng=-76.329999&callback=renderGeocode" ></script>
</head>
<body></body>
</html>

Categories

Resources