Addeventlistener with Ajax Not Working Well

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



Leave a reply



Submit