javascript - Having an issue with AJAX call on Paste event jQuery -
i trying pasted contents of form text field trigger ajax action connects php script deal data , sends relevant response.
the php script working know problem isn't there.
the jquery function works perfectly, alerting whatever pasted text field if this
$(document).ready(function(){ $('input').on('paste', function () { var capture = this; settimeout(function () { var url = $(capture).val(); alert (url); }, 100); }); });
but when try add ajax business fails.
i'm doing wrong don't know correct way it. way i'm calling ajax same method use in whole bunch of other scripts , works fine in must it's being called.
i've tried (left off doc ready save clutter) :
$('input').on('paste', function () { var capture = this; settimeout(function () { var url = $(capture).val(); }, 100); var data = { 'action': 'myaction', 'security': $( '#my-nonce' ).val(), 'url' : url, 'check' : check }; $.post(myajax.ajaxurl, data, function(response) { alert(response); } });
and tried :
$('input').on('paste', function () { var capture = this; settimeout(function () { var url = $(capture).val(); var data = { 'action': 'myaction', 'security': $( '#my-nonce' ).val(), 'url' : url, 'check' : check }; $.post(myajax.ajaxurl, data, function(response) { alert(response); } }, 100); });
and i've tried setting url var directly in data var :
var data = { 'action': 'myaction', 'security': $( '#my-nonce' ).val(), 'url' : $(capture).val(), 'check' : check };
but nothing working.
i suspect settimeout function. there specific way of firing ajax call when using settimeout?
just clarity. i'm trying trigger ajax call on paste event.
try increase time, mean settimeout(function(){... ,1000} try experimenting different times.
if answer post call eating time.
Comments
Post a Comment