w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Angular JS cancel $http call before calling a new $http
You need to create a new canceler for each request, because once it's resolved it can't be used again. See here for an updated plnkr.

Categories : Http

make http call from within another http call in angular
This psuedo code will work fine. The then is a callback for the async operation. See promises in angular for more detail. You are correct that the flow of the code execution will continue, but the callback (then) will still fire when the response is returned. So, this means that if you are binding to $scope inside the then, all will be fine and the data will bind into the model.

Categories : Angularjs

Why use $http in Angular instead of jquery's ajax?
My understanding is that there are a couple reasons the first is preferred: $http is testable. It's actually possible to stub out the backend that it uses and test $http requests without actually sending requests. $http does some common "stuff" for you, such as setting the content type to 'application/json' for you on POST requests. $http returns a "promise" similar to other areas in angular, which means .success, .done are consistent with angular. jquery also allows for similar, but the syntax is slightly different. $http success and error callbacks will execute inside of angular. If you use jQuery, then it might be necessary to call $apply, which can be tricky in some cases. $http works without jQuery. So if you don't have some other reason to include jQuery, you could possibly sav

Categories : Javascript

Is Angular http request call when a variable scope change?
While the question is unclear, I believe what you are referring to is a $watch setup on a scope property. If you make a normal request, such as this: $scope.myResource = 'path/to/resource'; //could be used use without $scope for this example $http.get($scope.myResource) //etc the call is just made once, because that's all it is told to do. If you want it to update when the path "myResource" changes, then do this: $scope.$watch('myResource', function(newPath) { //watching $scope.myResource for changes $http.get(newPath) //etc }) Now, when the value of $scope.myResource changes, the $http call will be again, this time requesting the new path.

Categories : Http

After Angular.js $http request, call complete function regardless of success or failure of promise
I'm not the world's greatest expert in Angular.js but understand you can do as follows : whatever.then(function() { // success code here }, function() { // error code here return true; // return anything that's not undefined (and not a `throw()`) to force the chain down the success path at the following then(). }).then(function() { // "complete" code here }); You are essentially forced to contrive something from one or more .then(), which is a $q promise's only method.

Categories : Ajax

What is the best practice for making an AJAX call in Angular.js?
The best practise would be to abstract the $http call out into a 'service' that provides data to your controller: module.factory('WidgetData', function($http){ return { get : function(params){ return $http.get('url/to/widget/data', { params : params }); } } }); module.controller('WidgetController', function(WidgetData){ WidgetData.get({ id : '0' }).then(function(response){ //Do what you will with the data. }) }); Abstracting the $http call like this will allow you to reuse this code across multiple controllers. This becomes necessary when the code that interacts with this data becomes more complex, perhaps you wish to process the data before using it in your controller, and cache the result of t

Categories : Angularjs

Ruby "&&" causes internal server error on Rails ajax call and "and" doesn't. What's the difference between the two?
&& has strong precedence and and has low precedence. @buddyship.involve? current_user && @buddyship.update(buddyship_params) is the same as @buddyship.involve?(current_user && @buddyship.update(buddyship_params)) and @buddyship.involve? current_user and @buddyship.update(buddyship_params) is the same as @buddyship.involve?(current_user) and @buddyship.update(buddyship_params)

Categories : Ruby On Rails

Angular: JSON data in template (avoid extra AJAX-call)
I believe extra AJAX call is absolutely fine. The performance benefits that you realize with embedded JSON in script is not worth the trouble if you consider the maintainability of your approach. This is a standard pattern with most of the AJAX enabled web apps. There may be other ways to improve performance such as server side caching and browser caching of response.

Categories : Angularjs

Angular resource (ngResource) won't make the AJAX call when called inside a function
You are declaring $scope.onFileRead as a function. What is calling onFileRead? When you move the call outside of the function, it is being run as part of initialization. What provides the input file? Probably bind to the onFileRead function from something in your DOM.

Categories : Angularjs

jQuery Ajax:- How to remove pending ajax call and active recent ajax call?
You can do like this. var CurrentAjaxReq = null; if(CurrentAjaxReq != null) { CurrentAjaxReq.abort(); } CurrentAjaxReq = jQuery.ajax({url: '/xyz.php', success: function(data) { CurrentAjaxReq = null; //do something } });

Categories : Ajax

Writing a custom http server, does supporting AJAX require extra code over HTTP GET?
AJAX is fine, it's just GET (or occasionally POST) requests which are formatted exactly the same on the server side. The difference on the server is, they'll typically go to a different "servlet" (or method in your C code) to be answered. Typically, the answer may be XML, JSON (serialized data for Javascript) or perhaps an HTML fragment (without or tags, just the content of a or something.). Or it could just be a 200 OO response indicating "success". On the browser side, AJAX is requested & used from Javascript within a page; with the results then either pasted into the DOM via innerHtml (for HTML fragments), or built into the DOM via Javascript (for JSON). The second option is less performant. Your first typical use-case might well be an autocomplete for a search-box, or somet

Categories : C

jQuery-How to call multiple ajax calls in one ajax call
Not possible in most cases Each ajax call involves the browser sending information to a server at a particular URL. If you reduced the browser code from two ajax calls to one ajax call, the server would receive less information, the browser would not receive some information it is getting now, and/or the server would perform fewer operations. If you control the server code, you might be able to change the server code to be able to do both operations in one step. Only then could you change the browser code.

Categories : Jquery

Ajax call (b) within callback of another ajax call (a) executes before (a) completes
You are executing ajaxB here: ajaxB(1) I think what you want to do is either return a function from ajaxB or find a way to pass the isPublic flag to your ajaxA function like: ajaxA(ajaxB, 1); function ajaxA(callback, isPublic){ FB.api('/me', function(response) { //ajax call(a) ajaxAdata = response.id; callback(isPublic); // this completes before ajax call(a) completes } }

Categories : Javascript

Difference between XML Over HTTP & SOAP Over HTTP
SOAP is a specialization of XML, as it has a schema, such as http://www.xmlsoap.org/soap/envelope/, whereas XML is more general. For using GET, you can read through this discussion: http://www.coderanch.com/t/463869/Web-Services/java/SOAP-request-HTTP, but basically SOAP is done via POST, though Axis2 appears to have support for GET, as a way to have SOAP work in a world where REST seems to rule. And, according to this IBM article (http://www.ibm.com/developerworks/xml/library/x-tipgetr/index.html) SOAP 1.2 introduces GET. As you mentioned, SOAP is a standard, so there are tools that can easily work with it, including dynamic client generation, as shown in this question, dynamic proxy soap web service client in java?, whansere the client generates the stubs needed upon connection. If y

Categories : Web Services

ASP.Net Web API call resulting in an HTTP 404 - "/Home/" being inserted in API call?
Your ajax request is taking the relative path in order to make the call. You have to provide a full path to your api. Try this: $.ajax({ url: "/full/path/to/api/comment/AddComment", or $.ajax({ url: "/api/comment/AddComment", If your api is hosted on your server's root.

Categories : Asp Net Web Api

only one ajax call from javascript loop instead of looping multiple ajax calls
JS-Call: $.post('update_page_positions.php', {'myArray': m}, function(data, statusText) { // This block is optional, fires when the ajax call is complete } ); AJAX-Handler: <?php include("connect.php"); $myArray = json_decode($_POST['myArray']); // do stuff with $myArray here. ?>

Categories : PHP

stop further ajax call until previous call completed in window scroll event .
I would add some bool flag indicating whether loading products is in progress. You should check the flag as a first action in scroll handler. The flag should be set to true when you enter to the if statement, and reset to false on ajax complete handler.

Categories : Jquery

Why ajax call is waiting for others to finish how to run a specific call with highest priority?
I would look at what is really needed. Do you really need 12 concurrent ajax calls per user/session? Your going to incur serious server issues processing that many requests. I see a lot of requests go to the same URI; does it make sense to wait until one of those requests are finished before processing the next? Is there a way to "bundle" your requests into one? or fewer? Chatty interfaces tend to lead to issues down the road. You could keep a tally of how many concurrent requests you have going and never let it go above a threshold, queuing requests that do, unless one is "High priority". But seriously rethink making that many requests at a time. Update Since you are making requests to multiple outside locations, based on one use action. Have the one user action make a single request

Categories : Asp Net

Bing Map v7, Direct call vs Ajax Call. Delay on Callback Function
One thing you might want to look at doing to speed things up is to perform the geocode on the server side. You could do this right in the ShowMap function. You can find information on how to use the Bing Maps REST services in .NET here: http://msdn.microsoft.com/en-us/library/jj819168.aspx

Categories : Javascript

Unable to retrieve value in AJAX POST call. [Used AJAX, MVC ASP.net, .net framework 4.0]
you need to spe4cify the content type as JSON $.ajax({ type: "POST", url: $("#urlprefix").val() + 'AssetManagement/SaveNew', data: JSON.stringify({ del: del }), contentType: 'application/json', success: function (d) { console.log('here'); return false; }, error: function (msg) { } });

Categories : C#

how to change type ajax call to controller of option "serviceUrl" in ajax autocomplete jquery devbridge with CodeIgniter?
I fixed my problems, but data that contains values for callback function when data is selected always null. What's up? MY SCRIPT: var options, a; $(document).ready(function(){ options = { serviceUrl:'controller_name/function_test', onSelect: function(suggestion) { alert('You selected ' + suggestion.value + ', ' + suggestion.data); } }; a = $('#search_by_user').autocomplete(options); }); MY FUNCTION IN CONTROLLER : public function function_test() { $query = isset($_GET['query']) ? $_GET['query'] : FALSE; //$query = 'te'; if($query) { $found = $this->model_name->get_list($query); $suggestions = array(); $data = array(); foreach($found as $row) {

Categories : Codeigniter

How to get a part of HTML webpage in a jQuery ajax Request? In other words how to filter the web page contents on an ajax call?
success:function(data) { var out = ""; $(data).find("your selectors").each(function(loop, item){ out += $(item).html(); }); data = out; alert(data); $("body").html(data); }

Categories : Javascript

How to stop call scroll function to call ajax when there is no more record
Maintain Flag. when ajax call then take a varible and assign a value to it like -false. and after call complete assing a value it - true. and every time when you ajax call just chekc the value of falg if it is true than call other wise not. like.. var flag=true; $(window).on('scroll', function() { if(flag) { flag=false; if ($(window).scrollTop() == ($(document).height() - $(window).height())) { $.ajax( { }, complete: function() { flag=true; } }); } } });

Categories : Jquery

ExtJS - Ajax Call Added to Store From Service Call
Just did some research - and found the two required SOAP classes within the docs. These files are indeed not contained within the src/data/soap directory... http://docs.sencha.com/extjs/4.2.2/source/Proxy3.html http://docs.sencha.com/extjs/4.2.2/source/Reader3.html#Ext-data-soap-Reader Here it's explained in detail, better than I ever could: http://docs.sencha.com/extjs/4.2.2/#/guide/soap

Categories : Ajax

How to call ajax call to form submit from ASP.NET MVC/ jQuery Dialog?
I double checked my jQuery files. They are linked correctly on the page. Make sure that you have included the jquery.unobtrusive-ajax.js script after jquery. If this is the case you don't need to be manually be subscribing to any .click events. Simply leave the Ajax.BeginForm to send the AJAX request. And if you don't want to rely on the Ajax.BeginForm then simply write a normal form: @using (Html.BeginForm("Action1", "Controller1", FormMethod.Post, new { id = "eProcess" })) { @Html.Hidden("eID", eId); @Html.Hidden("processName", "processName"); &l

Categories : Asp Net Mvc

Angular UI Typeahead with $http.get
You're providing angular with a callback function to call on http success. The http call is succesful long after your typeahead function returns. A big thing in javascript you have to wrap your head around is there's a ton of asynchcrony going on. You kick off an http request, give it a callback, and go away. Something in angular eventually calls your success function, and when your success function returns you end up back in angular land. Angular is nice in that on most events, it will check for changes for any values/expressions it knows it needs to watch for changes. It will then apply whatever behavior needs to occur on those changes. So Angular has a special process called $digest that does this. This behavior is often billed as angular's "2 way binding" feature. You want to take ad

Categories : Javascript

angular JS refresh a http
You're more than half way there! Here's a few slight tweaks to what you have that should do the trick. Turn your $http call into a function that we can invoke repeatedly - refresh(): Agenda.controller('Contacts', function($scope, $http) { $scope.refresh = function() { $http.get('php/contacts.php').success(function(data) { $scope.jsonContacts = data; }); } // call it initially $scope.refresh(); }); And then simply use ng-click to call the new refresh() function that we added above: <section class="agenda" ng-app="Agenda"> <ul ng-controller="Contacts"> <li ng-repeat="contact in jsonContacts"> <div class="col1">{{contact.contact_id}}</div> <div class="col2"&g

Categories : PHP

where should i use the $http in angularjs? -> difference between factory and service
Services are instantiated, only once, the first time they are called. They're used to share logic and expose data between controllers, for example. Controllers are the glue between the view and the model, like in any MVC framework. Running it at the start of the app or not has nothing to do with doing the $http request from a controller or from a service. Mae the http request when you need it. Notice that controllers are instantiated when angular finds <div ng-controller=whatever>... . If your http request is there, it'll be triggered. There was a similar question about services and factories a few weeks ago and another one about injecting a service in a controller.

Categories : Angularjs

What is difference between HTTP methods GET, POST, PUT and DELETE
But what is the disadvantage if we don't follow this above rule, suppose to insert a record i used GET method. Search engines access your pages using GET requests, so if you did this, google's crawler might insert records that you didn't want. Often, people will use POST for any kind of ajax request, with the actual action in the request's body. There's nothing very wrong with this, but the feature is there for you to use, so you might as well use it.

Categories : Dotnet

Difference between onLoad and ng-init in angular
ng-init is a directive that can be placed inside div's, span's, whatever, whereas onload is an attribute specific to the ng-include directive that functions as an ng-init. To see what I mean try something like: <span onload="a = 1">{{ a }}</span> <span ng-init="b = 2">{{ b }}</span> You'll see that only the second one shows up. An isolated scope is a scope which does not prototypically inherit from its parent scope. In laymen's terms if you have a widget that doesn't need to read and write to the parent scope arbitrarily then you use an isolate scope on the widget so that the widget and widget container can freely use their scopes without overriding each other's properties.

Categories : Angularjs

How to call local MVC 4 function inside ajax call
The problem is using server side helper function in the separate js file. If you need to have ajax call in the separate js file, set @TokenHeaderValue() value to a hidden field and read the value of hidden field in the js file.

Categories : Asp Net Mvc

Ajax call web service call error: undefined
I'm afraid that your code will never work due same domain policy (it's possible to send information to any origin , but it's invalid to receive information from origins violating this policy). If the API doesn't provide a jsonp version, you'll need perform the ajax request to a page on your site and access the api using server side logic contained on this page. This page on your site would be a proxy to communicate with this external service. This would be a sample method of what you need on server side public string GetPassage(string passage) { using (var c = new System.Net.WebClient()) { string url = "http://www.esvapi.org/v2/rest/passageQuery?key=IP&passage=' + strSearch + '&options=include-passage-references=true"; return c.DownloadString(Server.Ur

Categories : Asp Net Mvc

Angular $http vs service vs ngResource
Decided I'll formulate this into an answer since in the comments we worked out basically what you wanted to know: Using $http or $resource the results can still be cached, you pointed out the reasons to use one over the other really in your question. If you have a RESTful interface then using $resource is better since you'll end up writing less boiler-plate code that is common to a RESTful interface, if you're not using a RESTful service then $http makes more sense. You can cache data either way http://www.pseudobry.com/power-up-http-with-caching/ I think putting $http or $resource requests into a service just generally works out better because you want to have access to the data from multiple locations and the service acts as a singleton. So, basically you can handle any kind of cachi

Categories : Angularjs

Angular $http, $q: track progress
I see you have already edit your own code, but if you need a more overall solution, keep reading I once made a progress solution based on all pending http request (showing a indicator that something is loading, kind of like youtube has on the top progress bar) js: app.controller("ProgressCtrl", function($http) { this.loading = function() { return !!$http.pendingRequests.length; }; }); html: <div id="fixedTopBar" ng-controller="ProgressCtrl as Progress"> <div id="loading" ng-if="Progress.loading()"> loading... </div> </div> . Hardcore For my latest project it wasn't just enought with just request calls. I started to get into sockets, webworker, filesystem, filereader, dataChannel and any other asynchronous calls that use $q

Categories : Ajax

Getting a simple get using angular-$resource or $http
http://en.wikipedia.org/wiki/Cross-origin_resource_sharing You are violating the single origin policy by trying to XHR data from a domain external to the domain that delivered the invoking JS. Data retrieved with XHR must originate from the same host and port the site is served from. This is put in place to protect against cross site scripting attacks. You can work around this with JSONP (I suspect there is a seperate issue with your JSONP call, post it?) or by including the correct headers in the response from your API, Access-Control-Allow-Origin: *;

Categories : Angularjs

Delay an angular.js $http service
Interesting question! As you mentioned yourself, $timeout is the most logical choice for a delayed call. Instead of having $timeout calls everywhere, you could push a response interceptor that wraps the $http promise in a $timeout promise, as conceptually outlined in the documentation of $http, and register it in one of your configuration blocks. This means all $http calls are affected by the $timeout delay. Something along the lines of: $httpProvider.interceptors.push(function($timeout) { return { "response": function (response) { return $timeout(function() { return response; }, 2500); } }; }); As a bonus to your "to simulate a bad connection?", you could reject or do absolutely nothing randomly, too. Heh heh heh.

Categories : Angularjs

How do i use the actually implementation of $http in angular.js test?
The only valid scenario I can think of for you to do that is to perform end-to-end tests. In such a case, you should use the passThrough method of the request handler returned by the when method of the ngMockE2E.$httpBackend service. More information on that matter here.

Categories : Javascript

AJAX: Getting ajax call javascript function
you can use firebug in firefox. It allows you to have breakpoints in javascript code. You can click on the script tab of firebug and select your script file and provide breakpoints at all AJAX calls and see which AJAX is being called last.

Categories : Javascript

Sending an AJAX call before all other AJAX calls
UPDATED: Have one method on an interval that sets up the 'session'/local-storage var refreshing = false; var intervalID; $(document).ready(function(e){ var delay = 1234; intervalID = window.setInterval(setupInterval, delay); }); function setupInterval(){ refreshing = true; $.ajax(URL).done(function(r) { //do stuff setupStorage(r); refreshing = false; }); } function setupStorage(info){ //setup whatever here } OLD: Could you use some logic in your ready function to gate what you need to do? So basically call one ajax call -> if false, just schedule your latter methods, otherwise run the setup one and on completion schedule the latter method. Some pseudo-code: var refresh = false; $(document).ready(function(e){ $.ajax(URL).done( function(r) { if(r) {

Categories : Javascript

ajax how to pass a dom element to ajax call
If you have many of these fields, perhaps you could give them IDs and pass the appropriate one with your AJAX call. Then do what you need to do with it, and return the ID of what needs to get updated in your callback. Then you could do something like var val = $('.landscape_type#'+id).val();

Categories : Jquery



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