简体   繁体   中英

How to retrieve onClick/onChange data using xmlhttp

I'm relatively new at all this, and the search to answer this question has been killing me. Note that I may be asking the wrong question, and maybe even the wrong terminology, but for what it's worth:

As a site user, I'm trying to "navigate" through an internal aspx site using the xmlhttp object in VBA. While I'm able to access elementID's on certain site pages by using obvious URL lines, certain ElementID are dynamically generated, and thus unavailable until after, for example, the user makes a selection from a menu. The info is loaded as a result of some sort of onChange/onClick/javascript/postback function. Is there a way to retrieve this dynamic information? Furthermore, is this even the right approach?

Note: I can do all this using the IE object, but I'm really trying to avoid it for performance reasons.

Upon document inspection, the webpage side code shows:

<select name="ctl00$plcContent$Item1$Tabs$tabServices$Services$ddServiceCats" onchange="javascript:setTimeout('__doPostBack(\'ctl00$plcContent$Item1$Tabs$tabServices$Services$ddServiceCats\',\'\')', 0)" id="ctl00_plcContent_Item1_Tabs_tabServices_Services_ddServiceCats">
<option selected="selected" value="00000000-0000-0000-0000-000000000000">Select Service Category</option>
<option value="3f44517e-135a-466a-8440-9b1250d5285b">Kites</option>
<option value="7ec669b7-4d2c-4216-b19e-491faa13995a">Bikes</option>
<option value="f0bb692f-3df7-4c04-80d4-7e2b4a2805c3">Tikes</option>
.
.
.

The VBA I'm using to access the webpage is below:

With xml
    .Open "GET", BASE_URL3, False
    .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
    .Send ([no idea what to write here for the purposes of this question])
End With

The goal is to identify the elementID of a subcategory of "Bikes" (for instance, like 'tires') that gets loaded after we figure out how to "select" a main category (the subcategory's elementID value is dynamic).

Please let me know if I need to post more code.

Thanks again for you help.

I believe the root of your problem lies in difficulty separating what happens on the client side with JavaScript vs. what gets executed on the server side (VBA I assume).

You are also mixing your metaphors when you talk about "site" when I think you mean a Page as well as confused about URLs and HTML elements on the Page.

To be honest I don't fully understand what you are describing and what you are trying to do.

To answer your question directly: yes you can retrieve dynamic information that gets sent from the server via an xmlhttp request. Hopefully you are using a framework to execute that request on the client side and the callback method from your xmlhttp request will contain the data payload (response) from the server. Without looking at the code that is being executed its difficult to give you detailed direction.

If for some reason you do not have access to the callback method of your AJAX request you can also introspect the DOM structure of the resultant page but you again need to know what you are looking for (ie which element/s were updated as a result).

Post some coed and perhaps we can help you along.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM