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 the following code in my file to load a div with HTML
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>
I have the following code: <div class=editor-field> <%: Html.TextBoxFor(model => model.MyId) %> <%: Html.ValidationMessageFor(model
Let's say you have the following chunk of code: <div id=container> <someelement>This is any
I have the following code: $bind = new COM(LDAP://CN=GroupName,OU=Groups,OU=Division,DC=company,DC=local); When I execute it from
I have the following code: SELECT <column>, count(*) FROM <table> GROUP BY <column> HAVING
I have following code <div class=img> <img src=image/1.jpg class=img_s style=display:none; /> <img src=image/2.jpg class=img_s
I have the following code <div id=element1 style=display:none></div> <ul> <li id=item1>Item 1</li> <li id=item2>Item
I have the following code: <div id=sub-title-div> Hello world </div> #sub-title-div { background: #FFE640;
I have the following code that will check to see if the div text

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.