HaLo2FrEeEk Posted November 1, 2009 Share Posted November 1, 2009 First let me apologize if this is in the wrong forum, it has to do with both Javascript and ASP, but there is no ASP forum. Also, prepare yourself for a long read. I've been going through the source code for a site that I go on frequently. It's the homepage for Bungie Studios, creators of Halo. It's a very well-developed page, very professional, and as I'm going through it I'm noticing a lot of javascript functions __doPostBack(). These seem to control the ajax-like dynamic loading that the site does. Most of the functions are formatted like this: javascript:__doPostBack('ctl00$mainContent$findStatsLinkButton','') From what I understand, doPostBack is supposed to be something like this: __doPostBack(eventTarget, eventArgument) So using the example from above, "ctl00$mainContent$findStatsLinkButton" is the eventTarget, the object that will be recieving the returned data, and eventArgument is blank, meaning no arguments are passed. I want to make sure I'm understanding this right, there is a single form on the page: <form name="aspnetForm" method="post" action="/Online/Default.aspx" id="aspnetForm"> And this javascript: <script type="text/javascript"> //<![CDATA[ var theForm = document.forms['aspnetForm']; if (!theForm) { theForm = document.aspnetForm; } function __doPostBack(eventTarget, eventArgument) { if (!theForm.onsubmit || (theForm.onsubmit() != false)) { theForm.__EVENTTARGET.value = eventTarget; theForm.__EVENTARGUMENT.value = eventArgument; theForm.submit(); } } //]]> </script> And these hidden inputs: input type="hidden" name="ctl00_masterScriptManager_HiddenField" id="ctl00_masterScriptManager_HiddenField" value="" /> <input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /> <input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" /> <input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" /> <input type="hidden" name="__BNETSTATE" id="__BNETSTATE" value="[realllllly long unrelated (I think) text]" /> <input type="hidden" name="__VIEWSTATE" id=" __VIEWSTATE" value="" /> [...] <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="[another really long text, different on each pageload)" /> Which means that when a doPostBack link is clicked, it sets the hidden input "__EVENTTARGET" to the eventTarget value sent to the function, sets the hidden input "__EVENTARGUMENT" to the eventArguement passed (if any,) then submits the form. Since the form's action is "Online/Default.aspx" that means that the information is posted to that page, right? So basically it's posting all the input's values to Online/Default.aspx, then returning the result to eventTarget. Is there a reason the eventTarget value is formatted like it is? Here's an example of a portion of the page that can be updated: <div id="ctl00_ctl00_mainContent_haloStatRotator_bodyCountAllAjaxPanelPanel"> <div id="ctl00_mainContent_haloStatRotator_bodyCountAllAjaxPanel" jq="0"> <img id="ctl00_mainContent_haloStatRotator_allImage" src="/images/halo3stats/h3_characters/gif_large/brute_ultra.gif" style="border-width:0px;" /> <div class="infoblock"> <h4>Select Character:</h4> <select name="ctl00$mainContent$haloStatRotator$allDropDown" onchange="javascript:setTimeout('__doPostBack(\'ctl00$mainContent$haloStatRotator$allDropDown\',\'\')', 0)" id="ctl00_mainContent_haloStatRotator_allDropDown"> <option value="-1">-- Infantry --</option> <option selected="selected" value="0">Brute Infantry</option> <option value="1">Grunt Infantry</option> <option value="2">Jackal Infantry</option> <option value="4">Drone Infantry</option> <option value="6">Flood Carrier Form</option> <option value="7">Flood Combat Form</option> <option value="8">Sentinel Infantry</option> <option value="10">Engineer</option> <option value="-2">-- Leader --</option> <option value="11">Brute Leader</option> <option value="12">Drone Leader</option> <option value="-3">-- Hero --</option> <option value="14">Brute Hero</option> <option value="-4">-- Specialist --</option> <option value="17">Brute Specialist</option> <option value="18">Grunt Specialist</option> <option value="19">Jackal Specialist</option> <option value="20">Hunter Specialist</option> <option value="21">Flood Pure Form</option> <option value="-5">-- LightVehicle --</option> <option value="23">Shade</option> <option value="24">Ghost</option> <option value="25">Chopper</option> <option value="26">Recharge Station</option> <option value="-6">-- HeavyVehicle --</option> <option value="29">Wraith</option> <option value="30">Phantom</option> <option value="-7">-- GiantVehicle --</option> <option value="31">Scarab</option> <option value="-8">-- StandardVehicle --</option> <option value="34">Prowler</option> <option value="35">Banshee</option> </select> <ul class="kiatoday"> <li>KIA Today:</li> <li class="value">4,434,907</li> </ul> <ul class="kiaalltime"> <li>KIA All Time:</li> <li class="value">2,192,870,370</li> </ul> <p>Recruits compete for their postings as well as their gear.</p> </div> </div> </div> The image, "KIA Today", "KIA All Time", and "Recruits compete for their postings as well as their gear." are updated. How does the script know to update the div just by passing the id of the select tag to __doPostBack? The reason I'm asking this all is because there's stats on this page that you can only get by actually clicking the doPostBack links, but I need to get it for a contest I'm running, I need to poll some of that information to keep track of the contest's progress. I need to know if there's any way to post information to this page using php and get the result on my own server. That's the only way I'm gonna be able to get at the information I need for my server. Am I understanding the process of how this all works? And is there a way I can get at the information on my own server. Thank you for your time, anyone who takes the time to read this all, I appreciate it immensely, and to anyone that helps. Quote Link to comment https://forums.phpfreaks.com/topic/179790-__dopostback-help/ Share on other sites More sharing options...
KevinM1 Posted November 1, 2009 Share Posted November 1, 2009 To be honest, you'd be better off asking that question here: http://forums.asp.net/ Quote Link to comment https://forums.phpfreaks.com/topic/179790-__dopostback-help/#findComment-948734 Share on other sites More sharing options...
Adam Posted November 2, 2009 Share Posted November 2, 2009 I think I kinda get what you mean. My guess would be that there are 'submit' events attached to the forms else where in the code base which is triggering the AJAX functionality and suppressing the form actually submitting to another page. Can't obviously speculate how or where though. Quote Link to comment https://forums.phpfreaks.com/topic/179790-__dopostback-help/#findComment-949385 Share on other sites More sharing options...
HaLo2FrEeEk Posted November 3, 2009 Author Share Posted November 3, 2009 Well there's only the one form on the page, and I'm thinking that within the __doPostBack function there is an if...then statement that checks if the form has an onsubmit attribute, if it doesn't then it sets the hidden values and submits the form...but it's not actually submitting to a new page, I just want to know how the AJAX is firing. Quote Link to comment https://forums.phpfreaks.com/topic/179790-__dopostback-help/#findComment-949942 Share on other sites More sharing options...
Adam Posted November 3, 2009 Share Posted November 3, 2009 Well without actually seeing the site can only guess as to what's happening. As I said though, it's quite possible the "onsubmit" event is attached to the form else where in the JS. Quote Link to comment https://forums.phpfreaks.com/topic/179790-__dopostback-help/#findComment-950017 Share on other sites More sharing options...
HaLo2FrEeEk Posted November 4, 2009 Author Share Posted November 4, 2009 http://www.bungie.net/online/default.aspx That's the page I got all that code from. I didn't see an onsubmit event. Quote Link to comment https://forums.phpfreaks.com/topic/179790-__dopostback-help/#findComment-950641 Share on other sites More sharing options...
Adam Posted November 4, 2009 Share Posted November 4, 2009 It won't be a common HTML attribute like onsubmit="..." .. It'll be applied by the actual JS (or jQuery) tangled up in within their [rather large] framework. Take a look at.. http://www.quirksmode.org/js/events_advanced.html http://docs.jquery.com/Events Unfortunately as I said it is a big framework and I don't have time to look through to help you. Sorry! Quote Link to comment https://forums.phpfreaks.com/topic/179790-__dopostback-help/#findComment-951022 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.