w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Firefox appears to be queuing success functions of parallel ajax requests possibly because of setTimeout?
it turns out Firefox has a really stupid behavior that makes it queue up ajax requests to the exact same url so that their success functions get fired off one after another. The workaround for this is to append a random variable number to the ajx url itself. I'm not sure if this is a workaround behind a weird behavior or just a necessity due to firefox's caching method. Note: I'm actually passing the timestamp in deciseconds 1s/100 so if you ever had something that was firing more than once every tenth of a second you would need to divide the timestamp by a smaller value. change js to this: function doAjax(i) { var data = {json:"{"x": 1}"}; var rand = new Date().getTime() / 100; $.ajax({ url:"/echo/json/?rand="+rand, data:"json" }) .done(fu

Categories : Ajax

How to create a PHP chat app without continuous requests?
I am curious as to why you want to avoid all the technologies and methods developed specifically for these types of use cases but web sockets are the only other way to do it if you want to avoid comet. Your chat application needs to connect to the server the read the incoming chat messages. You have two choices: Polling This is continuously firing a new request off to the server at regular intervals to check for the messages. this is the typical AJAX style. Web Sockets Web sockets open one long running connection to the server. For a chat application if you are only interested in the newer browsers this is the way to go. As a bit of random information. Stack Overflow uses Web Sockets to check for any notifications.

Categories : PHP

JQuery AJAX request to Sinatra app blocked by CORS
I have found the answer to my problem. Initially, I was adding the header information to the Passenger web server via my sites-available/defaults file, and the Sinatra web service routes. Having set the CORS response headers in both places caused my response headers to have duplicate header information about the allowed origin, methods, etc. Once I removed the headers from the web server, and left them on the web service routes, my requests went through.

Categories : Jquery

error using setTimeout with AJAX request
The function must be referenced, not evaluated, so if you need to pass parameters, you'll have to wrap it in an anonymous function : var that = this; setTimeout(function() { $.ajax(that); } ,3000);

Categories : Javascript

usage of setTimeout function in AJAX
In that code, the setTimeout is being used to get updates from the server 5 times a second (which is probably too frequently). Without it, it only get the updates once (if updates() is ever called).

Categories : Javascript

Continuous status updates from a process using AJAX and PHP
I'll tell you what I did once, I'm no sure it's the best solutions but it worked. You should have an iFrame and set the target of the form to the iFrame <script> function showMsg(msg){ alert(msg); } </script> <form action="theCommandHandler.php" method="post" target="myIframe"> <input type="submit" value="Do A Command" /> </form> <iframe name="myIframe"></iframe> once posted to theCommandHandler.php, you should have a line of code like this in your php script: echo "<script>parent.showMsg('$idx/$count: File $f has been copied successfully to $tar_dir - $s');</script>"; You can send as many messages as you like back to client and they will invoke the showMsg function on the parent document.

Categories : PHP

jQuery json Ajax call no longer works after first time (including form submit, setTimeout)
To your ajax request add a cache: false. I had the same problem in my MVC application until setting that to false. You won't find good documentation on it though, it was something I dug up on a obscure website a while back. EDIT: I stand corrected, http://api.jquery.com/jQuery.ajax/

Categories : Javascript

jQuery Ajax Progress - how to not inherit progress percentage on different ajax requests?
This will store the value of _which for reuse when the handlers get called: function(_which, file_name) { $.ajax(... same as the code you have ... }(_which, file_name); What this does is create a closure that holds the values of the two variables you use in the callback (handler) functions you pass to the ajax call. By doing this you are still sharing the functions (e.g. progress) but you are not sharing the values of _which and file_name that are used in those functions. You would, of course, be adding the 1st and 3rd lines around your entire call toe $.ajax If you add more variables that are set outside but used inside those handler functions, you will need to add them to the closure as well. There are other ways to do this but this is minimal change to your code. For example

Categories : Javascript

AJAX GET REQUESTS
Try this var place="Paris%"; var a = $.ajax({ type:"GET", url: '@Url.Action("Weather_get","Weather1")', data: '{ "location":"' + place+ '"}', dataType: 'json', cache: false, success: function (data) { console.log(data); }, //succes error: function (data) { console.log(data); }//error }) //ajax;

Categories : C#

Differentiating between the two Ajax requests
Redesign your controller action method. Instead of placing conditional logic in your controller add an action method for each condition you need to satisfy and put the logic of which one to request in the view/markup. The best way to tell if you should load your consultant grid or a paged view of some search results is if the view/JavaScript performs an ajax request to the appropriate action method.

Categories : Asp Net Mvc

Ajax and PDO prepared requests
No, you can't use prepared statement between calls. No, it is not worth nor necessary in order to run the same query across different requests. However, you ought to use prepared statements in order to make your queries properly formatted. So, just create another PDO object every time your page called, and use prepared statement to run a query.

Categories : PHP

php ajax multiple requests
You can use the same file for multiple requests. You can supply parameters along with the AJAX request, either by including them in the URL after ? (they'll be available in $_GET and $_REQUEST) or by using the POST method and sending them as form data (they'll be available in $_POST and $_REQUEST). You can use the Javascript FormData API to encode this properly; see the documentation here. Using the jQuery library can simplify all of this. One of the parameters can then be a command or operation code, and the script can take different actions based on this.

Categories : PHP

Recursive ajax() requests
in that case the bug is in the server side code because the server should sent back the response only after 3 seconds. But I would recommend to use setTimeout() in the client side to restrict the request frequency Try function recursively_ajax(){ console.warn("begin"); $.ajax({ type:"GET", url: "./JvmInfoClass", success: function(data){ console.warn("get jvm info success"); setTimeout(recursively_ajax, 3000) } }); } recursively_ajax();

Categories : Javascript

Multiple each and ajax requests
The problem is that when acts on deferred objects, however sub doesn't return anything so when fires right away. So what you need to do is to collect all the deferred objects returned by the ajax calls and return them: var order = []; function sub(selector){ var deferredList = [] selector.each(function(){ var out = { "some":"random", "stuff":"here" }; var deferred = $.ajax({ type: "POST", url: "/test/url", dataType: 'json', contentType: "application/json; charset=utf-8", data:JSON.stringify(out), success:function(response){ $(this).attr("data-response",response); order.push(response);

Categories : Javascript

ignore non-ajax requests to action
You can do that by changing your request to 'POST' instead of 'GET'. Then the action should be decorated with [HttpPost] attribute like this: [HttpPost] public string Act() { }

Categories : Asp Net Mvc

Using dojo for grails ajax requests
This may be out of context since you are using an older version of Grails, but have a look at javascripts in newer versions of Grails. Particularly, library (optional) - The name of the library to include. Typical values include "jquery", "prototype", "scriptaculous", "yahoo" or "dojo" but plugins can contribute new providers. If the Resources plugin is installed, no link to the library will be rendered immediately. Rather, it will include the resource module with the same name as the library and let Resources do the rest. This means you must have a resource module declared with the same name, as if you had used an <r:use module="jquery"/> tag.

Categories : Javascript

How to identify responses from ajax requests
If you always want to have an order, maintain a variable to keep track of response from both the requests. Store responses from both the requests and then only when , you have shown response of first request, set the variable to show second response

Categories : Javascript

Secure Ajax Requests made by YII
I would do it by using the built in access control and extending CWebUser. It might seem lengthy but I think it's a clean solution. (We already have Yii::app()->user->isGuest and the like, so why not check all permissions here?) 1) Activate the access control filter. (In one controller or in /components/controller.php for all your controllers at once) public function filters() { return array( 'accessControl' ); // Tell Yii to use access rules for this controller } 2) Add an access rule In the concerned controller. (Sorry, I didn't bother with your index-action.) public function accessRules() { return array( [ 'allow', 'actions'=>['AddPermission'], 'expression'=>'$user->has(Permission::MODIFY_SERVER)' ], [

Categories : PHP

Bootstrap popover with ajax requests
Actually you can do this without reinitializing the popover: jQuery('.sideUpdate').popover({ html : true, trigger: 'hover', placement: 'left', container: '.chatSidebar', content: function() { return jQuery('#popover_content_wrapper').html(); }, selector: "a[data-aka=popover]" }); notice selector option that actually works similar to delegated events.

Categories : Ajax

Simultaneous independent AJAX requests
I've updated your fiddle: http://jsfiddle.net/22LN5/2/ I whipped up $.whenFaultTolerant, which will always return the promise in the event of completion or failure. Pass in a hash of deferreds, and out comes a hash of results! This is not a complete solution but I hope it is a good step in the right direction. $.whenFaultTolerant = function(things) { var remaining = Object.keys(things).length; var outputs = {}; var dfd = $.Deferred(); $.each(things, function(key, thing) { thing.always(function(data) { outputs[key] = data; --remaining || dfd.resolve(outputs); }); }); return dfd.promise(); }; Usage: $.whenFaultTolerant({ suggestqueries: $.getJSON("http://suggestqueries.google.com/complete/search?q="+$("#search")

Categories : Javascript

Returning a Variable and ajax requests
This is caused by the asynchronous nature of AJAX and the fact that you can't return from a callback. The sequence of events is this: You request the part (getPart()) by using an AJAX call. Within the AJAX call (post) you provide an anonymous function that us supposed to be called when the AJAX call is done. Because it is an asynchronous call, the JS continues executing, i.e. JS continues to the line after your getPart call, which is console.log('pid: '+pid); JS will output pid: undefined because the var pid has been declared but not defined in the line before. JS will continue whatever is next until the response from the AJAX call comes back. When the response comes back, it will execute the anonymous function from earlier. At the end of that function, it sees return id;, however, ther

Categories : Jquery

Mootools: wait until all ajax requests are done
http://mootools.net/docs/more/Request/Request.Queue In addition to these events there is an onEnd event that is fired when all the requests have finished. I'm going to extend the example from the documentation: var myRequests = { r1: new Request({ url: '/foo1.php', data: { foo1: 'bar1'}, onComplete: function(text, xml){ console.log('myRequests.r1: ', text, xml); } }), r2: new Request({ url: '/foo2.php', data: { foo2: 'bar2'}, onComplete: function(text, xml){ console.log('myRequests.r2: ', text, xml); } }) }; var myQueue = new Request.Queue({ requests: myRequests, concurrent: myRequests.length, onEnd: function() { console.log('Everything is done!'); }, onComplete: funct

Categories : Ajax

ajax requests within extjs widgets
I'm assuming this JS was retrieved from a server and is running in a browser. If so, it's not easy to read files with JS from within a browser. "stuff" can come from the server - perhaps via an AJAX call - or you might determine "stuff" via other logic in your JS. I know this is not a particularly helpful answer, but if I discouraged a newbie from trying to read text files using JS, then it's a good answer.

Categories : Javascript

How use afterInterceptor on Ajax Requests in Grails?
To support both ajax and non-ajax request, you have to do some content negotiation and return the respective response. Here's an example straight from the documentation: import grails.converters.JSON import grails.converters.XML class BookController { def list() { def books = Book.list() withFormat { html bookList: books json { render books as JSON } xml { render books as XML } } } } UPDATE: I'll leave the original answer in place as reference and context. Here's an answer/suggestions to your intended question. Assuming your non-ajax call is working, and you're able to acquire the user object from the model that's passed into your trackPageView closure, can you confirm the following: are you calling the exact same url on ajax and non-ajax calls ar

Categories : Grails

Ajax.ActionLink making two requests
I suspect that you have some other javascript file included in your page which is AJAXifying all links. Something along the lines of: $('a').click(function() { $.get(this.href, function(result) { }); return false; }); So you get 2 AJAX calls - one as a result of the jquery.unobtrusive-ajax.js script and the other as a result of your custom script. Look at all the scripts that are included in your view and start removing them one by one until you find the smoking gun.

Categories : Ajax

Multiple Ajax Requests per MVC 4 View
I redesigned the way I do my context now. I have my context then I implement IDbContextFactory<TContext> called DefaultContextFactory<MyContext> and I inject them. In the Repository I have in the public constructor _context = contextFactory.Create();. Then throughout the repository i just use _context.WhatEver() and its fine. I also did in the ModuleLoader Bind<IRepository>().To<DefaultRepository>().InTransientScope() in order to make every call to it create a new repository! I don't need a repository factory because I only have one repository!

Categories : C#

making many ajax requests instead of one request
You should see two requests : one for $.ajax() one for load() The most likely cause of multiple requests is that the delegated click handler is attached multiple times. It needs to be attached once, not once per row. You may be able to reduce the two requests to one as follows : var $pard_admin = $("#pard_admin").on("click", ".deleteArticle", function(event) { event.preventDefault(); var $row = $(this).closest('tr'); $.ajax({ url: "../pard_site/view/delete.php", type: "POST", data: { "deleteId": $row.find('td:first').text() }, success: function() { $row.remove();//or similar, depending on exactly what should disappear from the interface on successful delete. } }); });

Categories : Jquery

Directing all AJAX requests to https
As far I remember the value of %{HTTPS} can only be on if it is not aviable the key simply won't exists. If you don't post data the AJAX request will follow normal redirects however redirecting the AJAX request to https will cause a cross site request (that includes different protocols and subdomains) which is normally forbidden. There is a techique called CORS that allows such things. For implementing that you need to output the folowing http header: Access-Control-Allow-Origin: http://example.com There you need to exchange the domain with your actual one. Than you can also directly query the HTTPS resource without redirecting. If you have installed mod_headers you can use this line in your .htaccess file: Header add Access-Control-Allow-Origin "http://example.com"

Categories : Ajax

How to catch AJAX requests in Webbrowser
If I were you, I would've injected my own script into every page after it's been loaded. This a script that captures all AJAX requests and informs the application. Using the following code, you may capture every AJAX request made by jQuery (Haven't tried, but I don't think it works for non-jQuery AJAX requests). $.ajaxSetup({ beforeSend: function() { // before sending the request }, complete: function() { // after request completion } }); It's not even a code, but it can give you a clue for what you want to do. Surely using this method, you're gonna need to somehow communicate with your application. For instance, I'd use my made up protocol and a new window command so that my Delphi component will be able to capture and parse the event. As I said there

Categories : Ajax

Only last of multiple ajax requests gets completed
It's at least partially because each new XMLHttpRequest is being set to the same global x, which can only keep 1 of them. This means later references to x.readState and x.responseText aren't always referring to the "correct" instance. You'll want to declare x when or before setting it so it's scoped and unique to each Ajax request: var x = new XMLHttpRequest(); For more info, see Difference between using var and not using var in JavaScript.

Categories : Javascript

Do GET requests in AJAX load all images?
When an AJAX request returns HTML, that's all that happens — the HTML text is returned. If you never add that HTML to your DOM, then that's the end of it. If you do add the HTML to the DOM, then that's when any <img> tags will be examined. If the image data at the given URLs is not available in the browser cache, then separate HTTP requests will be made. If you want to avoid that, you can use data URLs in your HTML, though as one should expect (with a grimace) that's complicated by the prevalence of Internet Explorer.

Categories : Javascript

How to deal with session timeouts in AJAX requests?
If you put namespace configuration aside and use "pure" beans configuration, you could customize the ExceptionTranslationFilter to make it bypass the configured AuthenticationEntryPoint in the case of an ajax request. An example of this is explained in details here. The idea of the ExceptionTranslationFilter is that it detects that an AuthenticationException or an AccessDeniedException as been thrown before executing the request. In these cases, normally it should launch the authenticationEntryPoint if the user is not logged in. In the case of an AccessDeniedException and the user is logged in, the ExceptionTranslationFilter would normally just return an http status code 403 (access forbidden). But, if you can customize the ExceptionTranslationFilter as in the blog post mentionned abo

Categories : Spring

How do you split up an AJAX response so you don't have to make several requests?
If your php processing page sends back JSON instead of html, you could expect the following: { "data1display": "<div>whatever</div>", "data2display": "<div>something</div>" } and then in your js success callback, you could do something like: var targetIdArray = ["data1display", "data2display"]; var responseJSON = JSON.parse(xmlhttp.responseText); for (var i = 0; i < targetIdArray.length; i++) { document.getElementById(targetIdArray[i]).innerHTML= responseJSON[targetIdArray[i]]; } If you want to stick with html in the response, you can add a class or ID to each part of the response and grab the correct nodes from the response using regular old jQuery selectors. Eventually, you may want to change your frontend framework though, so it may be even

Categories : PHP

SignalR connection freeze other ajax requests
Taking @bjornhol's answer a little further - the same issue of all SignalR requests (which were loading more AJAX) queuing up was happening to me too. I thought it was jQuery which was the issue but in actual it is the session state. For that controller if you can set the SessionStateBehaviour to ReadOnly or Disabled you will see the requests go through simultaneously. Please see this link too http://johnculviner.com/asp-net-concurrent-ajax-requests-and-session-state-blocking/ Hope this helps.

Categories : Jquery

Retry failed jQuery.ajax requests
I think your code is the right way to do it, wrap your call in a new Deferred and return it until all attempts are reached. You could try to include your recursive call inside a anonymous function to improve readibility maybe. I wrote it like that : function doAjax(ajaxArgs, attempt) { // the wrapped returned dfd var wrappedDfd = $.Deferred(); // your nested call using attempt counter (function nestedCall() { // if call succed, resolve the wrapped dfd $.ajax(ajaxArgs).then(wrappedDfd.resolve, function() { // update attempt counter attempt--; if (attempt > 0) { // try another call nestedCall(); } else { // max try reached, reject wrapped dfd

Categories : Jquery

python code to echo ajax requests
You need something to process your URLs. Have you tried Web.py It can get you started quickly. import web urls = ( '/(.*)', 'hello' ) app = web.application(urls, globals()) class hello: def GET(self, name): if not name: name = 'World' return 'Hello, ' + name + '!' if __name__ == "__main__": app.run()

Categories : Python

Trigger multiple Ajax requests at the same time
You should do it like this : var check = function() { ... }; $('#checkall').on('click',function() { $("ul li").each(function() { check(this);//to check it all use your function //other code }); }); I used this because I don't know which function are calling and what variable are you passing to.

Categories : Javascript

jquery ajax asynchronous requests error
This isn't a bug, it's caching. It's a lot more efficient for a browser to cache a resource for a while then have to go and get it every time someone wants it. This is fine for static resources, i.e. ones that don't change much but for a web service that returns different results frequently for the same URL you will want to disable the caching. If you control the server side code, add a Cache-Control: no-cache header to the response. You can disable caching in your jQuery but as far as I know, you have to use the ajax() function - there's no way to do it with get(). $.ajax({ url: "/php/mine/update_cells.php", success: function(result){ parseAndUpdateData(result); }, cache: false, dataType: 'json' });

Categories : Javascript

Two subsequent jquery ajax requests not working
Try to implement the error callback option. This will provide you with the necessary error information. You are now only implementing the success callback which not gets called when something went wrong. Optionally you can also implement the complete callback which will always be called after the ajax request was send. $.ajax({ type: "POST", url: "thankyou.php", data: sData, success: function () { // Yeah! }, error: function(){ // oops } });

Categories : Jquery

How to keep sending ajax requests until a response is received?
I think you should be able to do this with very little modification to that function. var intervalId = window.setInterval(function() { epost(<url>,<data>,function(error,response) { if (!error) { window.clearInterval(intervalId); } else { alert(response); // or handle error some other way } // do something with the data }); },2000); I'm not 100% sure that intervalId will be available to the closure but if not you can always make it like this: var intervalId; intervalId = window.setInterval(.... The only issue I can think of is if the ajax call takes longer then 2 seconds to return, in which case you may not clear the interval in time.

Categories : Javascript



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.