jQuery: Get request (GET/POST) parameters from ajax request in Javascript
I am using jQueryUI dialog to open a modal form on my site. The form has a hidden input to pass on an affiliate code that is passed in the query string, like
http://mydomain.com/page1_with_form?affiliate=Chuck%20Norris
http://mydomain.com/page2_with_form?affiliate=Chuck%20Berry
I am using a jQuery plugin to make grabbing the GET values easy.
Both of the 2 pages (page1_with_form and page2_with_form) load the same modal form my_affiliate_form.html in a dialog box. I have no problem doing something like this on the my_affiliate_form.html page
var affiliate_code = $.query.get('affiliate');
if (!affiliate_code) affiliate_code = "Non开发者_如何转开发e";
$('[name=hidden_affiliate_field]').val(affiliate_code);
This works just dandy, and my affiliate ends up being Chuck Norris and Chuck Berry.
The problem, is now I want to not only include the affiliate code from the query string, but also want to use a key that is representative of the page they loaded the form from, ie. page1_with_form and page2_with_form). For page1, the key might be "Public" and for page2 maybe "Private", or something like that.
Now I want it where my hidden field has a value of "Public Chuck Norris" when hitting this page http://mydomain.com/page1_with_form?affiliate=Chuck%20Norris and "Private Chuck Norris" when hitting this page http://mydomain.com/page2_with_form?affiliate=Chuck%20Norris
I am loading the dialog contents like this:
$('#modal-form-holder').dialog({
bgiframe:true,
width:width,
title: title,
modal:true,
resizable: false,
closeOnEscape: true,
draggable: false,
autoOpen:false
}).load("my_affiliate_form.html?affiliate_key=" + key, null, onComplete);
The value for key is getting filled in correctly, but if my_affiliate_form.html tries to grab the "affiliate_key" via $.query.get('affiliate_key') it is empty. This is because the query plugin in inspecting window.location, which hasn't changed.
How can I grab the request paraemeter in my_affiliate_form.html that came in the ajax request?
Sorry for being so verbose, I just want to make my question as clear as possible.
Set the value in your onComplete handler. Something like:
$('#modal-form-holder').dialog({
bgiframe:true,
width:width,
title: title,
modal:true,
resizable: false,
closeOnEscape: true,
draggable: false,
autoOpen:false
}).load("my_affiliate_form.html", null, function(responseText, textStatus, XMLHttpRequest)
{
onComplete(responseText, textStatus, XMLHttpRequest, key);
});
Then, in onComplete (which should be defined to take all four parameters), fill the affiliate_key field with key.
精彩评论