在多个页面上发布数据 [英] POST data on multiple pages

查看:101
本文介绍了在多个页面上发布数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将表单中的数据发布到多个页面上,但主要操作仍应为". 因此,单击后,它应该在同一页面上刷新,但POST数据也将转到另一个.php.我需要这样做,因为在另一个.php文件中,创建了一个图,该图又被嵌入到原始表单页面中.

I would like to post data from a form on multiple pages, but the main action should still be "". So after I click, it should refresh on the same page but the POST data would have also went to another .php. I need this because at the other .php file, a graph is created which is embedded back onto the original form page.

我尝试使用隐藏字段.我也可以进行graph.php?var1=3&var2=3等操作,但是我不想那样显示.

I've tried using hidden fields. I can also do graph.php?var1=3&var2=3, etc. but I rather not display it like that.

我对javascript不太熟悉,但是我觉得那是要走的路吗?

I'm not too familiar with javascript, but I feel like that would be the way to go?

推荐答案

是的,听起来您应该执行jQuery .ajax调用或使用XMLHTTPRequest.将其发布到所需的URL,并在返回结果后重新加载页面.

Yeah, it sounds like you should do a jQuery .ajax call or use a XMLHTTPRequest. Post to the URL's you need, and once you get the results back, reload the page.

var i = 0
var pages = 3
var fd = new FormData();    
fd.append( 'value1', $('form input').val() );
fd.append( 'value2', $('form textarea').val() );

$.ajax({
  url: 'http://example.com/page1.php',
  data: fd,
  processData: false,
  contentType: false,
  type: 'POST',
  success: function(data){
    i++;
    captureFunction();
  }
});

$.ajax({
  url: 'http://example.com/page2.php',
  data: fd,
  processData: false,
  contentType: false,
  type: 'POST',
  success: function(data){
    i++;
    captureFunction();
  }
});

$.ajax({
  url: 'http://example.com/page3.php',
  data: fd,
  processData: false,
  contentType: false,
  type: 'POST',
  success: function(data){
    i++;
    captureFunction();
  }
});

var captureFunction = function() {
  if(i != pages) return;
  location.reload()
}

我认为这不是开箱即用的方法,但是它将是您开始黑客攻击的一个很好的起点.

I don't think this will work out of the box, but will be a good starting place for you to start hacking at.

这篇关于在多个页面上发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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