No value is obtained when Ajax asynchronously attaches a value.

Source: Internet
Author: User

No value is obtained when Ajax asynchronously attaches a value.

The problem is that the Ajax function is called in JavaScript to attach a value to the hidden text box "hidname,
The value of hidname is blank when you call the function. However, if you alter the value of this field when reading the value of hidname, you can read the exact value,
At the beginning, I felt very strange. I had never been confused about why alter had a value, but I couldn't get the value without alert. Then I found out that it was
Ajax Asynchronization makes it difficult to execute a function called by five lines at the same time, so seven lines cannot get the value.

Function ()
{
If (OBJ! = NULL)
{
Ajaxcommon. getdata (obj. Value, getresult_callback); // 5 rows
// Alert (document. getelementbyid ("hidname"). Value); // 6 rows
VaR STR = Document. getelementbyid ("hidname"). value; // 7 rows
Alert (STR );
}
}

Function getresult_callback ()
{
Document. getelementbyid ("hidname"). value = "1 ";
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.