使用Javascript网址发布表单

编程入门 行业动态 更新时间:2024-10-15 12:29:11
本文介绍了使用Javascript网址发布表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我试图将表单提交给不是我自己的网站(salesforce与他们的网站到领导功能),我正在通过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 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网址发布表单

本文发布于:2023-11-28 16:01:51,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   网址   Javascript

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!