I am getting this error from a jquery script on a specific page which performs an ajax call... and as far as I know it is generally an error caused by a missing } or )... but I have looked through the code over and over again and cannot see anything that is missing. Are there any other possible reasons this error could be flagged?
$('#socialMedia img').click(function() {
var id = $(this).prop('id').toLowerCase();
$.ajax({
url: "./socialMedia/" + id + ".php",
success: function(msg) {
$('.socialLink').css('opacity', '0.4');
$(this).css('opacity', '0.9');
if ($('#Feed').css('display') != 'none') {
$('#Feed').slideToggle(400, function() {
$('#Feed').html(msg);
});
}
else
{
$('#Feed').html(msg);
}
$('#Feed').slideToggle(400);
// if ($('#'+id+'Script').length <= 0) {
// $('head').append('<script type="text/javascript" src="./script/' + id + '.js" id="'+id+'Script"></script>');
// }
//alert(msg);
}
});
});
EDIT: you can "see" (you won't actually see anything as the error causes the page never to be loaded) the page by going to http://www.luketimoth.me... and then clicking "contact.me" (it is an AJAX site, and I have not yet implemented any handling of url specifiers)
The problem is in the AJAX response at this URL:
http://www.luketimoth.me/pages/contact.me.php
The ending </script> tag actually causes the end of that script portion - double-slash comment syntax is for javascript, the HTML parser doesn't respect it and ends the script section right there.
Related
I have a website in blogger : www.watiqati.net
When I use inspect element in Chrome I see this error:
Uncaught SyntaxError: missing ) after argument list
this is the code :
};
_0x5efbx0["html"](_0x5efbx9)
}
, complete: function () {
$(".cover .Post:not(:first)")["addClass"]("cov");
$(".sided:eq(1) .Post:not(:first) .Snippet, .sided:eq(0) .Post:not(:first) .Snippet")["remove"]();
$(".broadcast")["each"](function () {
$(this)["find"](".current:not(:first)")["remove"]()
})
}
})
} else {
_0x5efbx0["parent"]()["remove"]()
}
});
$(document)["ajaxStop"](function () {
$(".broadcast")["each"](function () {
var _0x5efbx1a = 0;
var _0x5efbx1b;
var _0x5efbx1c;
var _0x5efbx1d = $(this);
I don't know what to do. I tried deleting to add , ; { } ( ) the same problem.
I'm going to go out on a limb here and say that the ELSE shouldn't even be there. When you strip everything out of your AJAX success and complete methods your code looks like this:
$(function () {
$["ajax"]({
url: _0x5efbx2
, method: "GET"
, dataType: "jsonp"
, success: function (_0x5efbx8) {
}
, complete: function () {
}
})
} else {
_0x5efbx0["parent"]()["remove"]()
}
});
But that is only after removing a giant chunk of code so who really knows...
EDIT:
After seeing the full code it just makes it more obvious that you're missing the IF for that section of code that is showing the error.
That script block starts at line 804 with:
<script type='text/javascript'>
/*<![CDATA[*/
$(function() {
$["ajax"]({
...
And has the error at line 1130 for an ELSE that has no matching IF and appears after the closure for the ajax code. You need to figure out what IF was meant to go at the start or remove the ELSE.
Your code is incomplete.
Line 839, opening for loop:
for (_0x5efbxa = 0; _0x5efbxa < _0x5efbx8["feed"]["entry"]["length"]; _0x5efbxa = _0x5efbxa + 1) {
Line 1114, closing for loop,
Line 1116, closing success function,
Line 1127, closing Ajax request.
Lines 1128-1130, probably belong to a different/missing loop, and are causing errors now:
} else {
_0x5efbx0["parent"]()["remove"]()
}
Line 1131, closing the anonymous function (remove it).
Now it probably will not work as intended, but the structure is correct so you can start debugging from there :)
After several hours of fruitless experimentation, web searches, consultation of the Jquery API docs and poring over seemingly related stackoverflow posts, I've decided my only hope to getting this to work is to turn to the community here. Hoping someone can give me some insight into why this isn't working and how to fix it!
Within the web app I'm developing, I use several interactive SVG images, sometimes with multiple instances on a single page. In order to prevent distinct SVG images from stepping on each others' toes, interactive elements within each all carry a "barcode" of sorts, appended to their id attribute. In turn, the barcode for each image is encoded in the id attribute for the svg tag. In order for the page to display the svg with the correct initial state, I need to get the id attribute from the svg immediately after loading and pass it to another script to set the correct attributes within the target SVG.
Individual SVG's are loaded via an AJAX call, thusly:
$(document).ready(function(){
//mapId is supplied in various ways in different contexts, for example:
var mapId = $("#mapId").name;
loadSvgMap(mapId);
}
function loadSvgMap(mapId) {
return jQuery.ajax({
url: "[% c.uri_for('/maps/update_map/') %]" + mapId,
success: function(result) {
if(result.isOk == false) {
alert("Bad response from server: " + result.message);
} else {
$("#som_map").load(result);
}
},
error: function(result, status, errorThrown) {
alert("Map retrieval failed: " + status + " " + result.status);
},
async: true,
dataType: 'text',
cache: false
});
}
At this stage, I need to get the id attribute of the SVG that was loaded. The problem is, the SVG does not seem to exist on the page when I try to do so:
$(window).load(function() {
var svg = $("svg")[0];
console.log(svg);
//returns "undefined"
}
The issue seems to be that the ajax call has not completed when the next block of code executes, so the SVG is not yet present in the DOM. I've tried using $.when within $(document).ready), and this is the method I would like to use, but it still doesn't seem to wait until the SVG is loaded:
$.when(loadSvgMap(mapId)).done(function(a) {
var map = $("svg")[0];
console.log(map);
//undefined
});
I have figured out a workaround, but it is not ideal because the request fires after every ajax request, not just those that change the SVG...
$(document).ajaxStop(function() {
var svg = $("svg")[0];
if (svg != null) {
var map = svg.id;
console.log(map);
// do other stuff
}
});
Having this fire after every ajax request does not break anything at the moment but if I can get the $.when method working properly, it seems that should be less likely to break things down the road. Any ideas?
When working with asynchronous functions the best place to put code like this is in the callback function—Which runs as soon as control returns from the initial asynchronous request. In this case it would be in the success attribute of your jQuery.ajax(.. call:
function loadSvgMap(mapId) {
jQuery.ajax({
url: "[% c.uri_for('/maps/update_map/') %]" + mapId,
success: function(result) {
if(result.isOk == false) {
alert("Bad response from server: " + result.message);
} else {
$("#som_map").load(result);
// grab id here
console.log($('svg').attr('id'));
}
},
...
Id's and class names in SVG are objects rather than strings of HTML so the id and class selector used by jQuery won't work. IE..jQuery only understands the HTML DOM and not the SVG DOM.
So, given something like:
<object id="svg" data="img/yoursvg.svg" type="image/svg+xml" height="50" width="50">
</object>
You can use something like this:
window.onload=function() {
// The Object
var a = document.getElementById("svg");
// The SVG document inside the Object tag
var svgDoc = a.contentDocument;
// One of the SVG items by ID;
var svgItem = svgDoc.getElementById("svgItem");
// Do something to it.
};
So the problem turns out to be the call to .load() nested within the original ajax function. The outer call just retrieves the location of a static svg file, which is then loaded into the page with the inner ajax call. Of course, .when() only knew about the outer call, so it was firing before the svg had actually loaded.
The solution was to have a separate ajax function for the "inner" call, using .html() to load the content, and call it from a nested .when():
function loadSvgMap(mapId) {
return jQuery.ajax({
url: "[% c.uri_for('/maps/update_map/') %]" + mapId,
success: function(result) {
if(result.isOk == false) {
alert("Bad response from server: " + result.message);
} else {
// Simply return the result
}
},
error: function(result, status, errorThrown) {
alert("Map retrieval failed: " + status + " " + result.status);
},
async: true,
dataType: 'text',
cache: false
});
}
function loadSvgContent(mapUrl) {
return jQuery.ajax({
url: mapUrl,
success: function(result) {
if(result.isOk == false) {
alert("Bad response from server: " + result.message);
} else {
$("#som_map").html(result);
}
},
error: function(result, status, errorThrown) {
alert("Map retrieval failed: " + status + " " + result.status);
},
async: true,
dataType: 'text',
cache: false
});
}
$.when(loadSvgMap(mapId)).done(function(mapUrl) {
$.when(loadSvgContent(mapUrl)).done(function(a) {
var svg = $("svg")[0];
var map = svg.id;
console.log(map);
// Works!!
});
});
Many thanks to #MikeMcCaughan and #ThomasW for pointing me in the right direction!
It's a php while with javascript codes. I want that this:
Check every 1 seconds that chat_status.html -text's: status = "offline"
Full code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
// jQuery Document
$(document).ready(function(){
function loadChatStatus(){
var status = ("http://tulyita.hu/chat/chat_status.html".text);
if(status == "offline"){
//this happens 1#
} else {
//this happens 2#
}
}
setInterval (loadChatStatus, 1); //Reload file every 1 seconds
});
</script>
but it isn't worked. :( Can someone help me?
I need the text from the "chat_status.html".
function loadChatStatus(){
$.ajax({
url: "chat_status.html",
cache: false,
success: function(html){
$("#status").html(html); //Insert status into the #status div
},
});
if($("#status") == "offline"){
//this happens #1
} else {
//this happens #2
}
}
??
You can use $.get() to load the contents from your server and do something with it in the callback. Example (not tested):
$.get('http://tulyita.hu/chat/chat_status.html', function (data) {
if (data === 'chat = off' {
// happens when offline
}
else {
// happens when online
}
}, 'text');
Note that the page's current content is chat = off and not offline. Please check the exact contents of data after implementing this in your code.
Also note that your HTML page has to be on tulyita.hu or you have to add an Access-Control-Allow-Origin header because of the same-origin policy.
First, don't declare the loadChatStatus function in .ready() but outside of it. Leave only the setInterval inside the .ready() function. And 1 second is 1000 ms. setInterval expects ms.
Second, use .load() to get the contents of the url, put it in a (hidden) div,and then check what it is. You cannot just do "string".text , as a string has no .text member.
I tried for several hours to get the following code working.
The code should be paused until the page is loaded. The problem that I'm encountering is that the AJAX is executing asynchronously. How would I force the code to wait before executing?
var i = 1;
function On_Success(){
i = i+1;
if(i<=10){
$('<div id="p'+i+'">b</div>').replaceAll('#b');
$('#p'+i).load('tabelle.html');
//here shoul be waited, til the page is loaded
On_Success();
};
};
function knopf(){
$('body').append('<div id="p'+i+'">a</div>');
$('#p'+i).load('tabelle.html');
On_Success();
};
Both Ajax and load have an on successs function that can be run when the response is fully returned.
$.ajax({
async: true,
type: "GET",
url: url,
data: params,
success: function(html){
//do stuff here
},
error: handleAjaxErrors
});
If you want to use load, there is a success callback as well:
$("#myDiv").load('/ajax/data/get', function() {
//do stuff here
});
The load function has a success handler:
$('#p'+i).load('tabelle.html', function() {
On_Success();
});
The success handler is only called after the ajax call completes successfully, and after the provided content has been added to the DOM.
You can see full documentation here:
http://api.jquery.com/load/
If you also want to capture error conditions on the client you will need to use the full $.ajax call as per #Chris's answer.
.load accepts a callback that runs when loading is complete; you can use this instead of the more verbose jQuery.ajax function, which will require you to write additional code to populate your element.
jQuery("#p", i).load("tabelle.html", function() {
//code to run when tabelle.html has finished loading
});
Change your code to the following. It should work:
var i = 1;
function On_Success() {
i = i + 1;
if (i <= 10) {
$('<div id="p' + i + '">b</div>').replaceAll('#b');
$('#p' + i).load('tabelle.html', On_Success);
};
};
function knopf() {
$('body').append('<div id="p' + i + '">a</div>');
$('#p' + i).load('tabelle.html', On_Success);
};
On another note, is it absolutely necessary that you should wait for one load to complete before populating the other divs? Why can't you do something like this:
function On_Success() {
var i = 0;
while(i < 11) {
$('<div id="p' + i + '">b</div>').replaceAll('#b');
$('#p' + i).load('tabelle.html');
};
};
Also, I'm not sure what the knopf function is doing. What should the value of i be in that function? How are you calling your code?
hoping some one can shed some light on my problem. Basicly I only want to execute a block of code if a certain DOM element exists. If it does I then perform a few bits and bobs and then call a function. However it complains that the function is not defined, suggesting that the function is not in scope. Below is the code :
$(document).ready(function ()
{
if ((document.getElementById("view<portlet:namespace/>:editSplash")!= null)) {
console.log("notifications scripted started");
// hide loading box/ notify on body load
$('.ajaxErrorBox').hide();
$('.loadingNotifications').hide();
$('.notifyWindow').hide();
getFeed();
// set up refresh button for reloading feed
$('.refreshFeed').click(function() {
$('.notifyWindow').hide();
$('.notifyWindow').empty();
console.log("notifications clicked");
getFeed();
});
// begin ajax call using jquery ajax object
function getFeed ()
{
$('.notifyWindow').empty();
console.log("ajax call for feed starting");
$.ajax ({
type: "GET",
url: "http://cw-pdevprt-05.tm-gnet.com:10040/notificationsweb/feed?username=uid=<%# taglib uri="/WEB-INF/tld/engine.tld" prefix="wps" %><wps:user attribute="uid"/>",
dataType: "text/xml",
timeout: 10000,
success: parseXml
});
};
// show loading box on start of ajax call
$('.notifyWindow').ajaxStart(function() {
$('.refreshFeed').hide("fast");
$('.notifyWindow').hide();
$('.ajaxErrorBox').hide();
$('.loadingNotifications').show("fast");
});
// hide loading box after ajax call has stopped
$('.notifyWindow').ajaxStop(function() {
$('.loadingNotifications').hide("slow");
$('.refreshFeed').show("fast");
});
$('.notifyWindow').ajaxError(function() {
$('.loadingNotifications').hide("slow");
$('.ajaxErrorBox').show("fast");
$('.refreshFeed').show("fast");
});
// parse the feed/ xml file and append results to notifications div
function parseXml (xml) {
console.log("xml parsing begining");
if (jQuery.browser.msie)
{
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(xml);
xml = xmlDoc;
}
$(xml).find("entry").each(function()
{
var $item = $(this);
var title = $item.find("title").text();
var linkN = $item.find("link").attr("href");
var output = "<a href='" + linkN + "' target='_self'>" + title + "</a><br />";
$(".notifyWindow").append($(output)).show();
});
}
}
else {
console.log("notifications not available");
return false;
}
});
If the DOM element exists I then try and call the getFeed function "getFeed();" however it comes back undefined. If anyone could shed some light on this it would be greatly appreciated.
Thanks in advance
It seems that you're calling getFeed before it is defined. Try moving the if statement to after the function definition. Note that this behaviour is actually implementation specific, so some browsers may work this way and some may not.
Oh - And seriously? view<portlet:namespace/>:editSplash for an id?
Problem solved - I moved my functions outside of the if statement. We live and learn lol :-)