Error while posting photo through facebook api only on IE9 - ajax

This is a javascript function to make an upload of a photo to facebook, via facebook api.
It works everywhere, except in Internet Explorer 9
var sTagsPostcard =
'[{tag_uid:' + sIdProfile + ',x:' + aPositonsTags[sIdLayoutPostcard][0] + ',y:' + aPositonsTags[sIdLayoutPostcard][1] + '},' +
'{tag_uid:' + sIdFriend + ',x:' + aPositonsTags[sIdLayoutPostcard][2] + ',y:' + aPositonsTags[sIdLayoutPostcard][3] + '}]';
var the_url = $('input[name="hdnDomain"]').val() + 'media/postcards/' + sPathPostcard
$.ajax({
type: "POST",
url: "https://graph.facebook.com/" + sIdProfile + "/photos",
data: {
message: 'MESSAGE',
url: the_url,
format: "json",
access_token: sToken,
tags: sTagsPostcard
},
success: function(data){
if($('html').hasClass('touch'))
$('form[name="frmCustomLayout"]').submit();
else
window.parent.location.href = 'https://apps.facebook.com/[APPLICATION_NAME]/?st=' + N_STEP_THANKS;
},
error:function(a,b,c){
if($('html').hasClass('touch')){
$('input[name="st"]').val(N_STEP_RESULT);
$('form[name="frmCustomLayout"]').submit();
}
else
window.parent.location.href = 'https://apps.facebook.com/[APPLICATION_NAME]/?st=' + N_STEP_RESULT;
}
});
The execution enters the error() and not the success() function, and those are the parameters a,b,c:
a: object error (or sth like that)
b: error
c: no transport
Any ideas for IE9?? thanks in advance

The javascript ajax calling the graph.facebook api it seems not to work in browsers like IE9 / IE8.
The trick to solve it was to make an ajax call to a local script, and through that use the facebook api to do the same post.
In this way in all browsers the posting is working,

Related

OpenWeatherMap API call 'icon' not working

I'm trying to make ajax call to display current weather info however, only 'icon' is not displaying. All the other items are working just fine.
function APIcalls() {
// URL to make API calls for current forecast
let currentForeCastUrl = "https://api.openweathermap.org/data/2.5/weather?q=" +
city + "&appid=0fb779217270dc1943ca287687bf9395";
$.ajax({
url: currentForeCastUrl,
method: "GET",
}).then(function (response) {
let temp = Math.round(((response.main.temp - 273.15) * 9 / 5 + 32));
$("#icon").attr("src", "http://openweathermap.org/img/w/" + response.weather[0].icon + ".png");
});
}

Ajax call for json fails in ie

My jquery ajax call for a json file fails in Internet Explorer.
All other explorers are doing good.
Code :
$.ajax({
url: myurl + "?randomid="+Math.random(),
datatype: "json",
mimeType:"application/json; charset=UTF-8",
success: function(data,status,response) {
var JSONdata = $.parseJSON(response.responseText);
alert("Success");
},
error: function(e1,e2,e3) {
alert(e1 + " " + e2 + " " + e3);
}
});
Internet Explorer throws the alert in the error section :
[Object Object] error No Transport
Thanks in advance for your help!
You have cross domain request.
You need to set this (before ajax call):
$.support.cors = true;

CRM 2011 json data.d.results undefined but URL shows data

I'm trying to do a simple odata query and the call is successful, but the results are always undefined. I've thrown the URL into the description, copy and pasted it, and it works just fine. I've tested dozens of different ways to see what the object is, and the results are undefined. What am I missing??
UPDATE: As mentioned below, part of the problem was referencing data.d.results. When I referenced data.d.results[0], I actually got the error message "Unable to get property '0' of undefined or null reference." I wanted to add that here because I found almost NO help when searching for that error message.
The final answer was a combination of:
data.d for only one result
correct casing for system fields; "resProd.Description" as opposed to "resProd.description."
Back to orig Question:
Below is the code I'm using:
function setOPDefaults() {
// Create lookup
var lookupItem = new Array();
lookupItem = Xrm.Page.getAttribute("productid").getValue();
if (lookupItem != null)
{
var guid = lookupItem[0].id;
}
var crmOrg = window.location.pathname.split('/')[1];
var serverUrl = window.location.protocol + "//" + window.location.host + (crmOrg == 'userdefined' ? '' : '/' + crmOrg);
var ODATA_ENDPOINT = "/XRMServices/2011/OrganizationData.svc";
var ODATA_PREP = serverUrl + ODATA_ENDPOINT;
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
// Tried both of the following URLS (obviously not at the same time)
url: ODATA_PREP + "/ProductSet(guid'" + guid + "')",
url: "http://crm/<<orgname>>/XRMServices/2011/OrganizationData.svc/ProductSet(guid'67BA90A3-39D8-E211-8D1E-0050569A6113')",
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
var resProd = data.d.results;
alert(resProd.length); // This is undefined
// Below is where I load the URL into description just for testing.
// When I copy and paste this URL into the browser, it pulls up results with correct data
Xrm.Page.getAttribute("description").setValue(ODATA_PREP + "/ProductSet(guid'" + guid + "')");
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert("Ajax call failed: " + textStatus + " - " + errorThrown + " || " + XmlHttpRequest.responseText);
}
});
}
You're acessing just one record, so try put something like that:
data.d
data.d.results is used for multiple results. Another thing you can do to validate the results is put your url directly in browser.
In such cases, I use Fiddler. You can use it to debug your http/https trafic.
Or. If you have crm 2011 RU 12, you can use built-in Chrome debugger. Press F12. In console tab - right click -> Log XMLHttpRequest

Jquery Ajax - Tumblr API v2

I'm trying to delve into the depths of the murky world of Tumblr, and can't understand how to get over the following error:
Uncaught SyntaxError: Unexpected token :
I believe it may be because I'm getting back json, but trying to use jsonp. Here's what I'm trying to send:
$(function(){
$.ajax({
type: "GET",
url : "http://api.tumblr.com/v2/blog/MyTumblrName.tumblr.com/info",
dataType: "jsonp",
data: {
api_key : "MyTumblrApi"
},
success: function(data){
console.log(data);
},
});
});
I get a 200 OK response, and the data but still the above error (which I don't understand and would like to know more about)
Tumblr also kindly points out the following, but I'm unclear on the specifics.
All requests made with HTTP GET are JSONP-enabled. To use JSONP,
append jsonp= and the name of your callback function to the request.
JSONP requests will always return an HTTP status code of 200 but will
reflect the real status code in the meta field of the JSON response.
Any help would be awesome, thanks!
Do what Tumblr is telling you to - add a callback function name to the request
myJsonpCallback = function(data)
{
console.log(data);
}
$.ajax({
type: "GET",
url : "http://api.tumblr.com/v2/blog/MyTumblrName.tumblr.com/info",
dataType: "jsonp",
data: {
api_key : "MyTumblrApi",
jsonp : "myJsonpCallback"
}
});
========================================================
EDIT: The console.log thing is a syntax error since I didn't actually test this code.
What happens to success? I don't really know. Try and find out :) It will probably be called but data parameter likely be null or something.
The issue here is that jQuery names it's callback parameter callback, where as Tumblr is expecting jsonp. Upon 200 response jQuery likely simply eval()s the response, which is why myJsonpCallback is actually called.
In case you don't want to use jQuery:
var tumblrFeed = document.createElement('script');
tumblrFeed.setAttribute("src", "http://api.tumblr.com/v2/blog/{blog.tumblr.com}/posts?api_key={your api key}&jsonp=callback");
document.getElementsByTagName("head")[0].appendChild(tumblrFeed)
function callback(data){
console.log(data);
}
I've created simple function for this purpose:
function jsonpRequest(opt){
var params = "";
var blogName = "{your blog name}";
var api_key = "{api key}";
if("selector" in opt){params = "id=" + opt.selector;}
if(("offset" in opt) && ("limit" in opt)){params = "limit=" + opt.limit + "&offset=" + opt.offset;}
if("callback" in opt){params += "&jsonp=" + opt.callback;}else{params += "&jsonp=callback";}
params += "&api_key=" + api_key;
var tumblrFeed = document.createElement('script');
tumblrFeed.setAttribute("src", "http://api.tumblr.com/v2/blog/" + blogName + "/posts?" + params);
document.getElementsByTagName("head")[0].appendChild(tumblrFeed)
}
How to use it:
jsonpRequest({offset: 50, limit: 5});
function callback(data){do stuff here ...}
Alternative usage:
jsonpRequest({offset: 50, limit: 5, callback: "nameOfMyAmazingCallbackFunction"});
function nameOfMyAmazingCallbackFunction(data){do stuff here ...}

How to use Jquery Ajax Cache, is there a useful plugin for that and how can i test it?

I am using the jquery $.Ajax property for getting some data from database as json and manipulating dom with that.
For example like this:
$.ajax({
type: "POST",
url: "TipsAndTricksService.asmx/postCommentForTT",
data: "{'ttID':'" + ttID + "','text':'" + answerText + "','authorOfTT':'" + authorOfTT + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(message) {
var a=message.d;
var newCommentDiv = document.createElement('div');
newCommentDiv.setAttribute('id',a.answerID+"_commentTT");
newCommentDiv.setAttribute('class',"answerDivStyCom");
var html = "<div class='leftUp'>"+
"<img alt='profilePic' src='images/profilepics/" + a.authorID + "_2.png'/>" +
"</div>"+
"<div class='middleUpStyCom'>"+
"<div class='middleUpUpStyCom'><a href='ProfileMain.aspx?pid=" + a.authorID + "' >" + a.authorName + " " + a.authorSurname + "</a></div>" +
"<div class='middleUpMiddleStyCom'>"+a.authorJobname+"</div>"+
"</div>"+
"<div class='leftDownStyCom'>"+
"<div class='leftDownUp'>+Şikayet Et!</div>"+
"</div>"+
"<div class='middleDownStyCom'>"+a.text+"</div>"+
"</div>";
newCommentDiv.innerHTML=html;
$(myDiv).parent().parent().prev().append(newCommentDiv);
$("#"+a.answerID+"_commentTT").hide().fadeIn(1000);
$(myDiv).prev().children("textarea").val("");
}
});
As you see: the url is a webservice function and it works fine.
The question is :
Is caching a default property of jquery ajax post request? if so how can i test it?
If not a default property, is there a good and safe plugin for that ?
Thanks
Caching "POST" requests is kind-of weird, and your browser won't want to do it because a "POST" is supposed to mean that you are doing something actively on the server. For "GET" requests, things are cached the same way the browser caches anything else, with the exception that jQuery will modify your "GET" URLs with dummy parameters if you tell it to (the "cache" property you pass in the argument object to "$.ajax()").
What sort of caching are you talking about? It would help to know that.

Resources