Internet Explorer JavaScript - newline characters crashing script - javascript

I have a onclick event in JavaScript that I have chosen to format as below:
<a href="" onclick = "
$('.white_content').html('<img src=\'/making.gif\'>');
$.ajax({
url: '/show_album.php?id=<?=$album['id']?>',
type: 'GET',
success: function(data){
$('.white_content').html(data);
},
error: function(){
alert('failed');
}
});
return false;">
In FireFox, this is fine, but in Internet Explorer 8 the script is crashing because of the way I have layed out the code in new lines instead the onclick attribute.
Does anyone know a good way to fix this? I am still developing this page and others using similar code and I would like to keep a clean layout as opposed to all on one line.
If I inspect the onclick attribute in Internet Explorer developer tools I find each line seperated by several strange boxes that I assume represent unknown characters, obviously in IE, this is causing the error.

do the following instead:
<script>
function myOnclick() {
$('.white_content').html('<img src=\'/making.gif\'>');
$.ajax({
url: '/show_album.php?id=<?=$album['id']?>',
type: 'GET',
success: function(data){
$('.white_content').html(data);
},
error: function(){
alert('failed');
}
});
return false;
}
</script>
<a href="" onclick="return myOnclick();">

Related

Changes made in .js not being reflecting when I debug in Visual Studio

I'm trying to debug problems in a javascript file. When I make a change to the file and start the Visual Studio Debugger (F5) a [dynamic] version of the javascript file shows up in the debugger and stops at my break point, but the change I made to the file is not reflected in the [dynamic] version. For example, here is the function in the javascript file:
function GetJobNotes(ScheduleID) {
var par = "ScheduleID='" + ScheduleID + "'";
$.ajax({
type: "Post",
url: "MaskingScheduleService.asmx/HelloWorld",
//data: par,
dataType: "xml",
//success: GetInfoSuccess,
//error: ProcessError
});
alert("ajax called");
}
and here is what shows up in the [dynamic] version of the file when debugging:
function GetJobNotes(ScheduleID) {
var par = "ScheduleID='" + ScheduleID + "'";
$.ajax({
type: "Post",
url: "services/MaskingSchedule.asmx/GetJobNotes",
data: par,
dataType: "xml",
success: GetInfoSuccess,
error: ProcessError
});
}
How do I get the [dynamic] version to match the code in my javascript file?
The issue is that there is an option in Chrome that breaks the updated js file. With that option, Chrome will block the changed js content and always use the previous js content.
Solution
When starting vs debugging under Chrome, please press F12 and then select Network menu.
This is an option called Disable cache
Check this option and then refresh your web page and it will load the latest version of the javascript file.

Internet Explorer console throws error when passing variable with ajax post

I have a js function
function getdata(gender,filtervals,limit) {
//alert("Hi");
$(".photo,.info").html('...Loading....');
jQuery.ajax({
type: "POST",
url: 'data.php',
data: {
filtervals : filtervals,
gender : gender, // This is where the error is mentioned
limit : limit
},
success: function(result) {
if(result){
$("#List").html(result);
$("#List").css('display','block');
}
}
});
}
I get an error in IE (Only in IE) console saying 'expected ":"' at line 169 which I have identified with by commenting that on the right side
This code works well on chrome and firefox but not on IE and some mobile browsers.
Been trying to narrow down why my entire javascript is not working on IE and some mobile browsers. After vetting my code through JsHint and other tools, I checked on IE console. And this seems to be the only problem.
Any help would be greatly appreciated as I have been breaking my head on thsi for a long time.

$.ajax not working in IE9 in case of font url

I want to know the time taken for the font to be downloaded while using font-face. Hence i am using the following code
$.ajax({
async: true,
type:'GET',
url: "fontPath/font.woff",
CustomData: {fontObjIndex: i}
success: function() {
console.log('font downloaded')}
});
so that i can confirm that a particular font has been downloaded in client side using font-face.
This method works well in all modern browsers except IE 9. Does $.ajax accept Font urls in IE 9?
Note: It didn't enter progress or fail functions either.
Edit : Sorry i entered the code wrongly there. The error is not in that line as it works in all other browsers and it still persists in IE9
Try this:
$.ajax({
async: true,
type:'GET',
url: 'fontPath/font.woff',
CustomData: {fontObjIndex: i}
success: function() {
console.log('font downloaded')}
});
Please apply the following code to work
$.ajax({
async: true,
type:'GET',
url: "fontPath/font.woff",
CustomData: {fontObjIndex: i},
success: function() {
console.log('font downloaded')}
});
IE has no console object when Developer tools is not open.. Try running your code by commenting your console.log and try again..
If you want to use console , you need to define that first if Developer tool's is not open..
if (typeof console === "undefined" || typeof console.log === "undefined") {
console = {};
REF : Jquery AJAX not working in IE9

How to get the blackberry uuid using javascript and web works

I am trying to find the device UUID using javascript with web works for devices with OS 7 and less.
The code I am using:
function getIdentityData(){
$.ajax({
type: "get",
url: "http://localhost:8472/blackberry/identity/get",
success: function(msg){
alert(msg);
}
});
}
as found in their documentation is not working, I never get the alert? https://developer.blackberry.com/html5/apis/blackberry.identity.phone.html
I have the following in my config file
<rim:permit>read_device_identifying_information</rim:permit>
<feature id="blackberry.identity.phone" />
Have you tried just blackberry.identity.PIN as documented here - https://developer.blackberry.com/html5/apis/blackberry.identity.html#.PIN

Jquery ajax() call fails in IE8

I have the following code for submitting data using ajax from forms of class ajax. this works perfectly in Firefox, Safari and Chrome but fails in IE.
ajax: function() {
$('form.ajax').live('submit', function() {
var form_ajax = $(this);
$.ajax({
url: form_ajax.attr('action'),
data: form_ajax.serialize(),
type: form_ajax.attr('method'),
dataType: 'script',
beforeSend: function(xhr) {
$('#ajax-bid-new .ajax-form-error, #ajax-bid-new .ajax-form-success').remove();
form_ajax.slideUp();
}
});
return false;
});
Please help - I am stuck here for past 2 days. I am returning a Javascript file from server to be evaluated inside browser. This works as expected in Firefox, Chrome and Safari, but IE receives it as a file and opens up the file download dialog.
What can I do in IE to make this work? I tried by dropping the following code in my application.js file (I'm doing a rails project btw)
// public/javascripts/application.js
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
I get the same behavior from IE even after writing the ajaxSetup block like above.
Looks like live doesn't work with submit in IE. Have you tried using a normal submit instead:
$('form.ajax').submit(function() {
To catch live form submit events in IE, instead of:
$("form").live("submit", function() { ... });
to
var submitHandler = function() { ... };
$("body").children().each(function() {
$("form", this).live("submit", submitHandler);
})
Point to be noted
IE caches AJAX requests really aggressively (more so than Firefox, anyway). You need to set the Cache-Control headers in the response appropriately if this is not right for your site.
change your content type, last time i fixed similar problem by changing content-type from application/json; charset=utf8 to just plain application/json
jQueries' bind and live behaviours along with the liveQuery plugin
LiveQuery plugin solved the problem http://github.com/brandonaaron/livequery

Categories

Resources