Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS - $http post gets executed after second click
    primarykey
    data
    text
    <p>I'm trying to perform AngularJS post request via $http. My code looks like this:</p> <pre><code> $http({ url: "cgi-bin/post_event.pl", method: "POST", data : jsonToSend, headers : { 'Content-Type' : "application/json", } }).success(function(data, status, headers, config) { if (status === 200) { console.log(data); } else { console.log(data); } }).error(function(data, status, headers, config) { console.log(data); }); </code></pre> <p>While looking via Firebug I see that this part of code gets executed, but none request is triggered towards server.</p> <p>Only when I click it again, request hits server and success method is being called.</p> <p>Anyone knows why's that? Or maybe I'm doing something wrong here...</p> <p>This code with jQuery works fine:</p> <pre><code> $.ajax({ url: "cgi-bin/post_event.pl", type: "POST", contentType : "application/json", data : JSON.stringify(jsonToSend), success : function (data) { console.log(data); CurrentEvent.eventname = ""; CurrentEvent.starttime = ""; CurrentEvent.eventLocation.longitude = ""; CurrentEvent.eventLocation.latitude = ""; $window.location.href = "#/host/my_events"; }, error : function (data) { // add error to $rootScope.errors } }); </code></pre> <p><strong>EDIT:</strong> Ah, sorry, I should be more detailed. This is called as callback after successful ajax request. Rest of the this code is just constructing jsonToSend.</p> <p>So first time this part is being called I can see in firebug it constructs $http request but I can't see it triggered on server.</p> <p>Next time I click on a button that does first time ajax request success method of this one is called (but id doesn't call it via callback from ajax, but it goes directly into success method)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload