Ajax Inquiry POST

137 views Asked by At
$.ajax({
  url: "http://www.roblox.com/My/Groups.aspx?gid=148530",
  success: function(data) {
    console.log(data);
    var gg = data
    function Post(){
      $.get(url,function(Data){
        var VS = Data.match(/id="__VIEWSTATE" value="(.+)"/)[1]
        var EV = Data.match(/id="__EVENTVALIDATION" value="(.+)"/)[1]
        $.post(url,{
          "__VIEWSTATE" : VS,
          "__EVENTVALIDATION" : EV,
          "__EVENTTARGET" : "ctl00$ctl00$cphRoblox$cphMyRobloxContent$GroupMemberAdminPane$dlMembers_Footer$ctl02$ctl00",
          "__EVENTARGUMENT" : 'Click',
        })
      })
    }
    Post()
  }
})

I'm trying to get it to log it the other way around, so the $.post request would show the data from that page (the ranks I'm trying to get).

Help please? I really need answers as fast as possible.

1

There are 1 answers

3
Tomalak On

I think you want something like this:

function postback(eventTarget, eventArgument) {
    return function (html) {
        var $html = $("<div>").append(html);

        $.post(this.url, {
            __VIEWSTATE: $html.find("#__VIEWSTATE").val(),
            __EVENTVALIDATION: $html.find("#__EVENTVALIDATION").val(),
            __EVENTTARGET: eventTarget,
            __EVENTARGUMENT: eventArgument
        });
    };
}

var url = "http://www.roblox.com/My/Groups.aspx?gid=148530",
    target = "ctl00$ctl00$cphRoblox$cphMyRobloxContent$GroupMemberAdminPane$dlMembers_Footer$ctl02$ctl00";

$.get(url).done(postback(target, "Click"));

What's going on here:

The function postback() creates another function and returns it. That function accepts an HTML string as its argument, parses out viewstate and eventvalidation and sends a webforms-compatible postback to a pre-determined target control. In effect it encapsulates the action of sending a webforms event.

The last line does the actual work: It GETs url and calls postback() (which produces the matching Ajax success callback function). Once the Ajax request returns successfully, the .done() callback is called which then triggers a click event on the control.

Notes:

  • Trying to fetch URLs from a different domain than the one the script runs on will fail (see same-origin policy).
  • Parsing HTML with regular expressions is strongly discouraged. As you can see, with something as powerful as jQuery doing it correctly is even easier to read.
  • You probably should include a sanity check to see if the target control even exists in the page before you post the event. (if ($html.find("#" + eventTarget).length) ...)
  • Semicolons. Use them.

Recommended reading: