2011-12-23 9 views
0

これまで私はこのコードを使用しました。私はaspxからaspxにデータを送信しているときに動作しています。aspxからaspxにデータを送る方法

<script runat="server"> 

    function formload() 
    { 
     alert("its working"); 
     if(Request.Form["field1"] != null){ 
      alert("its working"); 
      Response.Write("field1 : " + Request.Form["field1"] + "</br>"); 
     } 
     if(Request.Form["field2"] != null){ 
      Response.Write("field2 : " +Request.Form["field2"] + "</br>"); 
     } 
    } 
    </script> 
    </head> 
<body onload="JavaScript:formload()"> 
<script language="JavaScript">// change to text/javascript or even remove, no effect 
window.onload = function() { 
    formload(); 
}; 
</script> 
</body> 

私の目的は私がしたいです。私はこのコードを使用してい

PHPの場合は
protected void Button1_Click(object sender, EventArgs e) 
{ 
    RemotePost myremotepost = new RemotePost(); 
    myremotepost.Url = "http://172.16.126.32/Riyas/marggroup.com/get-current-openings.php"; 
    myremotepost.Add("field1", TextBox1.Text); 
    myremotepost.Post(); 
} 
public class RemotePost 
{ 
    private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection(); 


    public string Url = ""; 
    public string Method = "post"; 
    public string FormName = "form1"; 

    public void Add(string name, string value) 
    { 
     Inputs.Add(name, value); 
    } 

    public void Post() 
    { 
     System.Web.HttpContext.Current.Response.Clear(); 

     System.Web.HttpContext.Current.Response.Write("<html><head>"); 

     System.Web.HttpContext.Current.Response.Write(string.Format("</head><body onload=\"document.{0}.submit()\">", FormName)); 
     System.Web.HttpContext.Current.Response.Write(string.Format("<form name=\"{0}\" method=\"{1}\" action=\"{2}\" >", FormName, Method, Url)); 
     for (int i = 0; i < Inputs.Keys.Count; i++) 
     { 
      System.Web.HttpContext.Current.Response.Write(string.Format("<input name=\"{0}\" type=\"hidden\" value=\"{1}\">", Inputs.Keys[i], Inputs[Inputs.Keys[i]])); 
     } 
     System.Web.HttpContext.Current.Response.Write("</form>"); 
     System.Web.HttpContext.Current.Response.Write("</body></html>"); 

     System.Web.HttpContext.Current.Response.End(); 
    } 
} 

しかし、それは動作していないPHPするASPXの場合

.....クエリ文字列にないaspxからphpにデータを送ります。

答えて

0

興味深い...

、あなたはサーバー側の機能であるformloadを()、呼び出している、そうではありませんか?

これはあなたのJavaScript関数クライアントサイトのみを呼び出す必要があり、クライアントのサイト上で、正しくありません。

php/asp.net/jspに関係なく、別のサーバーに情報を投稿したい場合は、

単にあなたremotepostクラスのポスト機能でフォーム....

を使用し、あなたは、単にいくつかのHTMLタグを生成する...あなたのリモートサーバに投稿して、ページの読み込み機能ではありませんでした自動的にフォームを送信し、

それはいいですが、動作する必要があります。

最初の問題を最初に修正し、次にそれがどのようになるかを見てください。

+0

私はこの新しいplsコードを通じて私を助けている –

0

クエリ文字列にない場合は、代わりにPOSTデータとして送信してください。オンロード機能で

+0

私は何か考えましたか? –

1

下記のコードを含むようにPHPスクリプトを修正し、それが動作するかどうか確認してください。与えられた2行以外は何も必要ありません。

<?php 

print_r($_POST); 
関連する問題