Edge animate: How to preload JSON information? - json

I get the JSON info to the EdgeAnimate Stage (creationComplete Action) by this code:
$.getJSON('myJsonLink', function(data) {
});
Problem: the composition get's the info, after the animation starts.
But the info needs to be loaded before animation.
it's very annoying problem for which I can't find the solution for days...
Can You help?

The getJSON fires an XMLHttpRequest in an asynchronous mode, which means a request is sent, then we move on to the next iteration in the flow.
You may need to make your request synchronous instead, but unfortunatelly, getJSON does not support synch mode as far as I know so you should use the low-level $.ajax() method with the async property set to false:
$.ajax({
dataType: "json",
url: "myJsonLink",
data: data,
async: false,
success: function () {}
});

Related

On page load, async ajax call to load div content(html and js and css) result in deprecated error in chrome 80

On page load, async ajax call to load div(tab) content(html and js and css) result in "Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience." in chrome 80.
First time this problem happened. Second time onwards on click to div(tab) this error is not happening. jquery version is 1.12.3. Tried with setTimeout,
$(document).ready(function(){
$.ajax({
url: 'tabPage',
dataType: 'html',
async: true,
data:'tabId=1&searchedEmpUserId='+searchedEmpUserId+'&menuId='+menuId,
success: function(data) {
// load content from file into #content-holder
$('#content-holder').html(data);
}});}
... but same error is coming.
Tried with
$("#content-holder").load('tabPage?tabId='+tabId+'&searchedEmpUserId='+searchedEmpUserId+'&menuId='+menuId, function(){
unBlockUI();
});
..that also same error. If HTML response text is not set then only error is not coming.
Any help is appreciated.
What I understand from dig down the issue, ajax call is asynchronous but html() or load() is synchronous. So jquery send method call has to change so that async call can be done by default. So async param is replaced with async || true in jquery 1.12.3 min js. It worked for me.

Jquery mobile page List-view content not getting updated

I am new to phonegap jquery mobile app. In my app i have some pages and each page gets its content as a list-view using json. Now content will load only once i.e when we click on the page for the first time and that's the same case for every other page. Later even if the json gets updated it won't be shown in the list. I can notice the updated list-view only after i logout from the app. and then again i login to the app. i.e content will get updated only after i restart the session!
Take a look at this examples, one example uses xml to create a listview and other one uses a JSON file:
XML: http://jsfiddle.net/Gajotres/AzXdT/
JSON: http://jsfiddle.net/Gajotres/8uac7/
You are probably loading it in a wrong page event, if possible always use pagebeforeshow like this:
$('#index').live('pagebeforeshow',function(e,data){
$.ajax({url: "http://api.themoviedb.org/2.1/Movie.search/en/json/23afca60ebf72f8d88cdcae2c4f31866/The Goonies",
dataType: "jsonp",
jsonpCallback: 'successCallback',
async: true,
beforeSend: function() {
$.mobile.showPageLoadingMsg(true);
},
complete: function() {
$.mobile.hidePageLoadingMsg();
},
success: function (result) {
ajax.parseJSONP(result);
},
error: function (request,error) {
alert('Network error has occurred please try again!');
}
});
});
Also take a look at my other article, it will give you a better understanding of jQM page events flow: https://stackoverflow.com/a/14010308/1848600

MVC 3 jQuery UI autocomplete not displaying the results

I have searched many times and find examples which match my code structure perfect. Yet I am not getting the results from my ajax to display on the input box.
I get results from the POST that have been evaulated with firebug and everything looks great.
Here is the javascript im using.
<script type="text/javascript" language="javascript">
$(function () {
$("input.FamousPerson-List").autocomplete({
source: function (request, response) {
$.ajax({
url: "/FamousPeople/FPPAutoComplete",
type: "POST",
dataType: "json",
data: {
searchText: request.term,
maxResults: 12
},
success: function (data) {
response($.map(data, function (item) {
return {
value: item.DisplayName
}
}))
}
});
}
});
});
Here is a link of the actual code I am using on the web.AutoCompleteTesting Type just about any letter in one of the boxes below to invoke it.
Thanks.
If you look closely at the request being sent up, you'll notice that a callback parameter is being added. Weird, right? Since you're doing a local AJAX post, not a cross-domain (JSONP) one.
I noticed that your project includes jQuery Validate. According to this answer to a question dealing with a similar problem (performing a JSONP request instead of a normal JSON request even though you asked for one), it's a known issue in jQuery validate.
Judging by the other answer, you can change your version of jQuery or perhaps use a patched version of jQuery validate (found here).

jQuery $.ajax() is firing the server request but never gets response on google chrome only

I tested this on firefox and ie and worked. But when testing on chrome, I see in the firebug console that the request never loads.
This is the test page: http://gotune.to/index2.php
And here is the function + $.ajax() request.
function getProgress(id) {
$.ajax({
type: 'POST',
cache: false,
url: "getprogress.php",
//Pass our upload identifier as a parameter.
data: {uid: id},
success: function (d) {
//Get the output as an integer.
var progress = parseInt(d, 10);
//If upload progress is not 100, change bar percentage and update again.
if (progress != '100') {
$('#ProgressBar').css('width', progress + '%');
//We aren't done, update again.
getProgress(id);
}
}
});
}
UPDATE
Tried with
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus+" - "+errorThrown);
}
But still not working.
After a web research for this issue if found this:
Turns out it's a bug, in any webkit
based browser all ajax is essentially
blocked until the file upload is
complete. to bypass this you have to
dynamically create an iframe and run
the ajax requests from within it.
So is a problem of the webkit browsers, thanks #ifaour for your time.
THE BUG REPORT CAN BE FOUND HERE: https://bugs.webkit.org/show_bug.cgi?id=23933

jQuery AJAX request failing in IE

The following AJAX call is failing in IE.
$.ajax({
url:"{{SITE_URL}}/content/twitter.json",
dataType:"json",
error:function(xhr, status, errorThrown) {
alert(errorThrown+'\n'+status+'\n'+xhr.statusText);
},
success:function(json) {
...Snip...
}
});
The error function returns
Undefined
parsererror
OK
No request is made to the server so I don't think its a problem with the JSON.
Fixed, See #1351389
Fixed, I changed the content-type from application/json; charset=utf8 to just plain application/json.
I hate IE :)
Also to avoid IE super-caching try this:
var d = new Date();
$.ajax({
url:"{{SITE_URL}}/content/twitter.json?_="+d.getTime(),
...Snip...
That way each request is a new url for IE to get :D
For the caching problem why don't you simple use the cache: false parameter?
$.ajax({
url: "yoururl",
cache: false,
....
is this a copy/paste? the one thing that gets me all the time is leaving the last ',' in an object constructor. that is, most browsers JS accept:
o = { a:1, b:2, c:3, };
but IE chokes on this because the comma after the last item. change it to:
o = { a:1, b:2, c:3 };
and it works.
In newer versions of internet explorer (IE7) it is necessary to write the next line before calling $.ajax, otherwise it would never call the function:
$.ajaxSetup({ cache: false }); //this line before $.ajax!!!
$.ajax({
//codes
//codes
//codes
});
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.
One major problem with statically generated JSON and IE are the leading "commas", for examples this throws an error in IE:
{
"one":"hello",
"two":"hi",
}
Note the last comma.
What is the {{SITE_URL}} chunk giving is about. Try looking at the code in view source code of the browser. If the {{SITE _URL}} chunk has a trailing slash and that would make the request url:
http://modomain.com//content/twitter.json
Which could creep IE out?
IE: JSON not defined error resolved at
http://funkatron.com/site/comments/safely-parsing-json-in-javascript/
by using dataType: "json" and avoid parsing