Addeventlistener with ajax not working well
The second argument to addEventListener
should be a function. You're not passing a function, you're calling the function immediately and passing the result. Change to:
document.getElementById("showF").addEventListener("click", function() {
sacardatos('P1.txt','container');
}, false);
ajax inside addEventListener not working
Try this instead:
$('#submit').click(function(){ // Click handler
$.get('index.php',
{'user_id': '123213'}, // Data payload
function(resp) { // Response callback
alert(JSON.stringify(resp));
});
return false; // Prevent default action
});
ajax xhr.upload.addEventListener not working for cross domain call
When sending GET, POST methods cross domain, a "preflighted" requests is first send by OPTIONS method.
https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS?redirectlocale=en-US&redirectslug=HTTP_access_control#Preflighted_requests
It looks like you are getting 404 Not Found response. Make sure your request target URI return something such as 200 OK, by allowing OPTIONS method requests to be sent.
AJAX file progress not working / addEventListener('progress') does not work
The answer lay in the Service Worker which was also listening for fetch requests.
A detailed description of the problem can be found here:
https://github.com/w3c/ServiceWorker/issues/1141
Specifically adding this at the top of the Fetch Event Handler:
if (event.request.method === 'POST') {
return;
}
jQuery addEventListener + ajax
I found it working.
function attachEventsFid2() {
var main=$('.main-wrapper');
var btn = document.getElementById("btn-iphone4");
btn.addEventListener('click', function(event) {
event.preventDefault();
alert('clicked');
});
};
$(document).ready(function(){
attachEventsFid2();
});
<input type="button" id="btn-iphone4" value="click"/>
Fiddle: http://jsfiddle.net/Wwb57/2/
FYI: your provided code is also working. Check this fiddle: http://jsfiddle.net/Wwb57/6/
When I call .addEventListener(click, myFunction(i), false); It runs my function on the call and not on the click
addEventListener needs to assign the function variable. In your code you are calling the function immediately using (). To fix it you can remove them.
classname[selected].addEventListener("click", formating, false);
To pass argument to your function you can either wrap it in an anonymous function and call it or use bind (source):
classname[selected].addEventListener('click', formating.bind(null, event, arg1, ... ));
Related Topics
Where's the Connection Between Index.HTML and Index.Js in a Create-React-App Application
Jquery Jump or Scroll to Certain Position, Div or Target on the Page from Button Onclick
How to Stop User from Printing Webpages? Using JavaScript or Jquery
Change CSS Rule in Class Using Jquery
Retrieving Percentage CSS Values (In Firefox)
How to Check for Null Values in JavaScript
Is There an Equivalent of the _Nosuchmethod_ Feature for Properties, or a Way to Implement It in Js
Keydown Simulation in Chrome Fires Normally But Not the Correct Key
How to Get a Utc Timestamp in JavaScript
Cannot Use Attr with an Object in D3 V4
JSON.Stringify Output to Div in Pretty Print Way
Open a New JavaScript Window(.Open) Along with Its CSS Styling
Find the "Potential" Width of a Hidden Element
How to Get the Position of Element Transformed with CSS Rotate
Inherited CSS Values via JavaScript
JSON Datetime Between Python and JavaScript
Google Chrome Console.Log() Inconsistency with Objects and Arrays