php - jQuery ajax request awkward issue -


so have ajax request. when user clicks edit link, fetch id of entry , refresh page data of entry loaded form.

here's problem: works alert showing before ajax call. when leave out alert, ajax error (though id being posted) , php page reloads. moreover, works when put newdoc stuff success callback. exact same lines complete callback , page reloads. moreover, occurs in firefox only.

jquery('a.edit').on('mousedown', function (e) {     e.preventdefault();     var id = jquery(this).attr('data-title');     alert('test');     jquery.ajax({         url: document.location,         data: {             id: id         },         success: function (data) {             var newdoc = document.open("text/html", "replace");             newdoc.write(data);             newdoc.close();         },         error: function () {             alert('error');         }     }); }); 

what can do?

edit: must timing issue. noticed when click , hold edit link second or so, works fine. when short click, doesn't. tried wrapping ajax in settimeout(), didn't help. other ideas?

try use location.href in place of document.location,

jquery.ajax({     url: location.href,     data: {         id: id     },     success: function (data) {         var newdoc = document.open("text/html", "replace");         newdoc.write(data);         newdoc.close();     },     error: function () {         alert('error');     } }); 

location structured object, properties corresponding parts of url. location.href whole url in single string.


Comments

Popular posts from this blog

design - Custom Styling Qt Quick Controls -

Unable to remove the www from url on https using .htaccess -