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

  • Home
  • SEARCH
  • 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 5845283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:24:44+00:00 2026-05-22T12:24:44+00:00

I have try to post value from page a to page b via jquery

  • 0

I have try to post value from page a to page b via jquery ajax.
But when I need a onload event in the handle page. I tried 2 ways, but all failed. How to call correctly or it is a bug?

a.php

<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<script type="text/javascript">     
jQuery(document).ready(function(){
    $("a").click(function(){
     $.ajax({
         url: "b.php", 
         dataType: "html",
         type: 'POST', 
         data: "word="+"hello", 
         success: function(data){ 
            $("#show").html(data);
         }
      });
    });
});
</script>
<a href="#">click</a>
<div id="show"></div>

b.php

<script language="JavaScript">
   function callhello() {
       alert('<?php echo $_POST['word']; ?>');
       //many other code, for a test, I moved them. and replace a alert call.
   }
</script>
<body onload="JavaScript:callhello()"><!-- way 1, put onload here, not run -->
    Blah~~ Blah~~ Blah~~
<script language="JavaScript">// change to text/javascript or even remove, no effect
window.onload = function() {
  callhello();
};
</script><!-- way 2, put onload here, still not run. -->
</body>
  • 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-22T12:24:45+00:00Added an answer on May 22, 2026 at 12:24 pm

    When you insert HTML into your document, any scripts are executed with the document’s context. That means that window.onload refers to the load event of the current window. Given that the insertion is delayed (by waiting for the click event), the window.onload event has already been triggered. You can attach a function to the load event, but it will never be triggered.

    It’s probably best to put the function call straight into your script element:

    <script type="text/javascript"> // the language attribute is deprecated
      callhello();
    </script>
    

    This means that jQuery will execute the script as it’s added to the document.

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

Sidebar

Related Questions

I have a via with some jQuery function to get value from HTML element
I have problem when I try insert some data to Informix TEXT column via
I am making a page that accepts post data from any number of pages
I have a problem when I try put data from controller to form view
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have a small project I want to try porting to Python 3 -
I have encapsulated a backup database command in a Try/Catch and it appears that
I have uploaded some files to a directory under public and I try to
I have the following issue using java 1.4 I try to display a very
I have a quick little application and wanted to give a try to develop

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.