Form not sending because url I'm building somehow isn't accepted
Thanks for looking. I'm pretty new to JS and I'm hoping this is just a simple answer staring me in the face that I'm missing.
I'm working on a chunk of JS for sending a form to Sales Force. Sales Force needs a 'success' URL to redirect to. Instead of hardcoding it I want to detect the domain where the site visitor is and serve a thank-you page from that domain. Right now the site is in t开发者_JS百科esting and some less technical people will be handling the full launch (don't ask) and they don't want to have to go digging through JS files at launch time but still want to be able to test now.
You can see a commented out line, that one works but the URL I build doesn't.
var domainCustomerIsUsing = document.domain;
var thankYouURL = 'http://'+domainCustomerIsUsing+'/thank-you-newsletter';
var salesForceForm = $('<form>').attr('method', 'POST').attr('action', 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8').css('display', 'none');
// salesForceForm.append(createInput('retURL', 'http://google.com'));
salesForceForm.append(createInput('retURL', thankYouURL));
It is a jQuery form but the bit where I am trying to build the URL is not jQuery. I've removed bits of the form for client confidentiality but I think this shows everything I need to.
Thanks for looking!
Can you alert the result for the URL you build and the output from createInput
? This works for me just pasting it into the Chrome console on this page:
var domainCustomerIsUsing = document.domain;
var thankYouURL = 'http://'+domainCustomerIsUsing+'/thank-you-newsletter';
var url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
var salesForceForm = $('<form>').attr('method', 'POST')
.attr('action', url)
.css('display', 'none');
salesForceForm.append($("<input>").attr("name", "retURL")
.val(thankYouURL));
salesForceForm.submit();
My money is on $("<input")
being built incorrectly.
精彩评论