Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4121274
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:19:48+00:00 2026-05-20T23:19:48+00:00

I have the following code: <div id=parentDiv> <a href=someurl> … </a> </div> HTML inside

  • 0

I have the following code:

<div id="parentDiv">
    <a href="someurl"> ... </a>
</div>

HTML inside the div comes from the external source and I don’t know it’s structure and can’t control it.

I need to post some data when this link has been clicked. So I added an onclick event handler on the div element, hoping event will propagate, and posted data with jQuery ajax function.

This worked fine in all browsers but Safari – it doesn’t return any errors, calls the callback function but doesn’t reach the server for some reason. I write to database every time I get a request. Tried to manually load the post url in browser – works fine and record in db is created. Also tried FF and Chrome – works as expected.

When put an alert into callback function it’s being called but in Safari data = null.

$('#parentDiv').delegate( 'a', 'click', function()
{
    $.post('posturl', 
        { param1: 'test'}, 
        function(data)
        { 
            alert('data = '+data);
        },
        "json"
    );
});

Is it correct to expect AJAX working in this situation at all? And is there a better solution to this problem?

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T23:19:49+00:00Added an answer on May 20, 2026 at 11:19 pm

    This sounds like you need to combine delegate with the asynchronous AJAX. Note that this is almost never a good thing — the only real exception is when you want to do an AJAX request immediately before leaving a page.

    Your code might look something like this:

    $('#parentDiv').delegate( 'a', 'click', function()
        $.ajax({
          type: 'POST',
          url: 'posturl',
          { param1: 'test'}, 
          dataType: 'json',
          async: false
        });
    });
    

    This waits for the POST request to finish before continuing to follow the link. Note that this is superior to using location = url in a success callback as this solution allows normal browser action like middle-clicking to be followed as normal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have HTML like the following: <div id=move-me> <a href=#>I'm a link</a> </div> <div
I have the following HTML structure: <div><a href=link1>blah</a></div> <div><a href=link2>blah</a></div> <div><a href=link3.swf>blah</a></div> <div><a href=link4>blah</a></div>
Background I have the following html code: <div id=parent> <div id=child> I'm the child!
I have the following HTML code: <div id=summary_form> <textarea class=summary>Please fill in</textarea><br/> <textarea class=summary>Please
I have following code in HTML, and I would like to retrieve name12@host.com from
I have following code in html: <div> <div style=float:left;margin:0.5em> <span class=title>Label1</span><br/> <input type=text name=name1
I have the following code in my file to load a div with HTML
I have the following code: HTML: <div id=login class=transparent-div login_leaf_class> <input class=pointer login_fields_button id=submit_button
I have the following HTML markup: <div id=step1 class=step> <h1>Enter code</h1> <p><input type=text value=<%=
I have following code: <div contentEditable=true> Blah blah <a href=http://google.com>Google</a> Blah blah </div> Fiddle

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.