0

I'm trying to access some data from a request that is being made: ?sm-xml-search=1

I really don't know the best way to "hook" or "bind" onto this request ... since I can't seem to bind to the actual click event. My attempts at binding to an event just doesn't respond. So that's why I need to respond to the actual HTTP request.

How might I extract this information each time it's requested?


Is there not a way to extract data from a call?

dcolumbus
  • 9,596
  • 26
  • 100
  • 165
  • what do you mean "since I can't seem to bind to the actual click event"? And why do you need to extract this info client side? – Colleen Dec 06 '12 at 22:55
  • I realize the question is a bit vague... but I need to grab information from the request, such as an ID. – dcolumbus Dec 06 '12 at 22:55
  • 1
    incredibly. It's best to detail why you're trying to do something, what specifically is going wrong, and provide some code usually. – Colleen Dec 06 '12 at 22:56
  • There's really no code to supply ... bottom line is that there's a request being made and there's a response. The response contains the variable `?sm-xml-search=1` and I just don't know how to bind to that GET request. – dcolumbus Dec 06 '12 at 22:58
  • I see your edit: more specific than that. Show code for the click event. Explain why you need this data *client-side* – Colleen Dec 06 '12 at 22:59
  • I can't access the click event. I can't bind to it at all because it's being generated by the Google Maps API. I wish I could bind to the click event, but I just can't. At least I dont know how to. – dcolumbus Dec 06 '12 at 23:00
  • 1
    Ok. Again, why do you need this data client side? Also, if you get a little more specific, there's the possibility that there's an API callback for exactly this situation. – Colleen Dec 06 '12 at 23:02
  • A user will click on a "location" that's listed out using Google Maps API ... when the user clicks on this location, a call is made that contains the ID of the location selected. I need this ID to then save which location they've chosen. Server-side is an impossibility in this situation. – dcolumbus Dec 06 '12 at 23:03
  • 2
    No offense. But, did you read the Google Maps API documentation before coming here? – Alexander Dec 06 '12 at 23:06
  • great, makes sense (finally). Google Maps surely has this functionality built in-- see their docs https://developers.google.com/maps/documentation/javascript/reference#MapsEventListener (I don't know exactly where in their docs the exact listener you will need is, but if it's not at that link I'm sure it's somewhere else in there) – Colleen Dec 06 '12 at 23:07
  • also, second @Alexander. Please search the docs before coming to stackoverflow. This is where the common "what have you tried?" comment should be. – Colleen Dec 06 '12 at 23:07
  • ... the google documents are NOT going to help me in this situation. Google doesn't contain the ID, the application does. Sure the click event is generated using the maps API, but the call is not generated during this step. – dcolumbus Dec 06 '12 at 23:11
  • It's still not clear. When do you want to get the ID from the URL? If you're using PHP, it's a simple `$_GET['sm-xml-search']` call in your script. If you want to do something with it in the client, using JQuery, see this article: http://stackoverflow.com/questions/1403888/get-url-parameter-with-jquery` – Twisty Dec 07 '12 at 00:52

2 Answers2

0

You can actually get the calling url with

var pathname = window.location.pathname;

After that, you can use a regex to get the value you want:

var match = /.*sm-xml-search=(.*)$/.exec(pathname);
var urlParam = match[1];

The regex will return the matches if your parameter is the last. If not, you should use a delimiter (like &).

jaudette
  • 2,305
  • 1
  • 20
  • 20
  • Even if the call is made with AJAX? And there's no way to tell WHEN the call is being made. – dcolumbus Dec 07 '12 at 19:27
  • @dcolumbus If the call is made from Ajax, you can bind an event handler to `ajaxComlete` (see (doc)[http://api.jquery.com/ajaxComplete/]), then find if it is the address you need and parse it. – jaudette Dec 07 '12 at 21:10
0

jQuery('div.result').live("click", function(event) {

That works perfectly.

dcolumbus
  • 9,596
  • 26
  • 100
  • 165