简体   繁体   English

多个提交动作

[英]Multiple Submit Actions

I have a script given to me by another developer to send push messages to my Apps. 我有另一个开发人员提供给我的脚本,用于将推送消息发送到我的Apps。 I want to be able to send them from one page to both App types but cannot figure how. 我希望能够将它们从一页发送到两种应用程序类型,但无法说明如何。 Problem is I do not have any control over the pages on the server they are sent to. 问题是我无法控制将它们发送到的服务器上的页面。 If you look at the code the only differences in the two critical pieces of code are the Form action to send them to each Server page and the name of the App Id's...the other info remains the same. 如果您查看代码,则两个关键代码段中唯一的区别是将它们发送到每个服务器页面的Form操作和应用程序ID的名称...其他信息保持不变。

I also found a piece of javascript to submit to two places from one button but could not get it working with both... 我还发现了一个JavaScript,可以通过一个按钮提交到两个地方,但无法同时使用这两个地方...

I know from reading that I probably need an array...Could someone please show me some code with these in an array with a submit button to send them to their respective pages. 从阅读中我知道我可能需要一个数组...有人可以向我展示一些包含这些代码的数组,并带有一个提交按钮以将它们发送到各自的页面。

Thanks in advance... 提前致谢...

EDITED 已编辑

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="../../ScriptLibrary/jquery-latest.pack.js"></script>
</head>

<body>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<form name="push"  method="post" >
<input name="pushmessage" type="hidden" value="HAIR EXTENSIONS  ">

<p align="center">Notification Message:<br />
<textarea style="width: 280px; height: 150px; margin-bottom: 30px;     font-family: Verdana, Geneva, sans-serif; border-color: #000; border-        width: 1px; resize: none;" name="pushmessage" id="push-message">    </textarea><br />

<input type='button' class="inputbtn" name='Submit' value='Push' onclick='sendFormData()' />
<form/>

<script type="text/javascript">
function sendFormData() {
  var formURL1 = 'http://apple/iPhone-message';
var formURL2 = 'http://google/android-message';
var postData1 =     {'publishersid':'appdeveloper','username':'myself','pass':'mypassword','appid':' CommunityApp-i','topics':'test'};
var postData2 =     {'publishersid':'appdeveloper','username':'myself','pass':'mypassword','ap    pid':'CommunityApp','topics':'test'};

 submitForm(formURL1, postData1);
 submitForm(formURL2, postData2);
};
function submitForm(formURL, postData) {
$('#push-message').append('sending data to url : '+formURL+'\n');
$.ajax(
    {
        url: formURL,
        type: "POST",
        data: postData,
        success: function (data, textStatus, jqXHR) {
    $('#push-message').text('success');
        },
        error: function (jqXHR, textStatus, errorThrown) {
    $('#push-message').append('oops:error occured'+errorThrown+'\n');
        }
    });
}
</script>
</body>
</html>

You should not use native submit button (that triggers a page change) but use a ajax submit method using XHR object. 您不应使用本机提交按钮(触发页面更改),而应使用使用XHR对象的ajax提交方法。

You can take a look to this jquery plugin: http://jquery.malsup.com/form/ 您可以看一下这个jquery插件: http : //jquery.malsup.com/form/

you dont need to html form tag, you can do that with this piece of this code: 您不需要html表单标签,可以使用以下这段代码来做到这一点:

<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<form name="push"  method="post" >
<input name="pushmessage" type="hidden" value="HAIR EXTENSIONS  ">

<p align="center">Notification Message:<br />
<textarea style="width: 280px; height: 150px; margin-bottom: 30px;     font-family: Verdana, Geneva, sans-serif; border-color: #000; border-        width: 1px; resize: none;" name="pushmessage" id="push-message">    </textarea><br />

<input type='button' class="inputbtn" name='Submit' value='Push' onclick='sendFormData()' />


<script type="text/javascript">
function sendFormData() {
  var formURL1 = 'http://apple/iPhone-message';
var formURL2 = 'http://google/android-message';
var postData1 =     {'publishersid':'appdeveloper','username':'myself','pass':'mypassword','appid':' CommunityApp-i','topics':'test'};
var postData2 =     {'publishersid':'appdeveloper','username':'myself','pass':'mypassword','ap    pid':'CommunityApp','topics':'test'};

 submitForm(formURL1, postData1);
 submitForm(formURL2, postData2);
};
function submitForm(formURL, postData) {
$('#push-message').append('sending data to url : '+formURL+'\n');
$.ajax(
    {
        url: formURL,
        type: "POST",
        data: postData,
        success: function (data, textStatus, jqXHR) {
    $('#push-message').text('success');
        },
        error: function (jqXHR, textStatus, errorThrown) {
    $('#push-message').append('oops:error occured'+errorThrown+'\n');
        }
    });
}
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM