使用Javascript网址发布表单 [英] Post Forms Using Javascript URL

查看:89
本文介绍了使用Javascript网址发布表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将表单提交给不是我自己的网站(salesforce.com与他们的网站到领导功能),我正在通过javascript模式窗口进行。



基本上,一旦所有条目都经过测试并确保没有错误,我使用这个:

  if(error_count == 0){
$ .ajax({
type:POST,
url:[salesforce url],
data:first_name = + first_name +& last_name =+ last_name +& email =+ email +& firm =+ firm +& [salesforceid] =+ AUM +& [salesforceid] =+ custodian +& [salesforceid] =+ custodian_other,
error:function(){
$('。error')。hide();
$('#sendError') .slideDown('slow');
},
成功:function(){
$('。error')。hide();
$(成功)了slideDown(慢)。
$('form#callToAction')。fadeOut('slow');
}
});
}

如果在不使用JavaScript的情况下测试了表单,思考也许JavaScript处理url的方式是问题吗?



问题:数据未成功提交给Salesforce。再次,常规的HTML表单工作,JavaScript不。所以我将它定义为一个JavaScript问题。

解决方案

您无法创建XHR跨域请求,除非接收服务器允许它和浏览器支持CORS。然而,您可以像这样盲目提交,并假设成功:

  var $ form = $(< form> ,{
method:POST,
action:[salesforce url],
target:my-iframe
})。appendTo(body);
$ b $ var $ iframe = $(< iframe>,{
name:my-iframe
})。bind(load,function(){
$('。error')。hide();
$('。success')。slideDown('slow');
$('form#callToAction')。fadeOut 'slow');
$ iframe.remove();
$ form.remove();
})。appendTo(body);

$ .each((first_name =+ first_name +& last_name =+ last_name +& email =+ email +& firm =+ firm +& [salesforceid] =+ AUM +& [salesforceid] =+ custodian +& [salesforceid] =+ custodian_other).split(&)),function(index,value){
var pair = value.split(=);
$ form.append(< input>,{
type:hidden,
name:pair [0],
value:pair [1]
});
});

$ form.submit();


I'm trying to submit a form to a website not my own (salesforce.com with their web-to-lead function) and I'm doing it through a javascript modal window.

Basically once all the entries are tested and made sure there are no errors, I use this:

if(error_count == 0) {
                $.ajax({
                    type: "POST",
                    url: "[salesforce url]",
                    data: "first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&firm=" + firm + "&[salesforceid]=" + AUM + "&[salesforceid]=" + custodian + "&[salesforceid]=" + custodian_other,
                    error: function() {
                        $('.error').hide();
                        $('#sendError').slideDown('slow');
                    },
                    success: function () {
                        $('.error').hide();
                        $('.success').slideDown('slow');
                        $('form#callToAction').fadeOut('slow');
                    }               
                }); 
            }

If tested the form without using javascript and the url works, so I'm thinking maybe the way javascript handles the url is the issue?

The issue: the data is not getting successfully submitted to Salesforce. Again, regular HTML form works, javascript doesn't. So I've identified it as a javascript issue.

解决方案

You cannot make a XHR cross domain request unless the receiving server has allowed it and the browser supports CORS. You can however do a blind submit like this which will assume success:

var $form = $("<form>", {
    method: "POST",
    action: "[salesforce url]",
    target: "my-iframe"
}).appendTo("body");

var $iframe = $("<iframe>", {
    name: "my-iframe"
}).bind( "load", function () {
    $('.error').hide();
    $('.success').slideDown('slow');
    $('form#callToAction').fadeOut('slow');
    $iframe.remove();
    $form.remove();
}).appendTo("body");

$.each(("first_name=" + first_name + "&last_name=" + last_name + "&email=" + email + "&firm=" + firm + "&[salesforceid]=" + AUM + "&[salesforceid]=" + custodian + "&[salesforceid]=" + custodian_other).split("&")), function (index, value) {
    var pair = value.split("=");
    $form.append("<input>", {
        type: "hidden",
        name: pair[0],
        value: pair[1]
    });
});

$form.submit();

这篇关于使用Javascript网址发布表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆