The implementation method of post delivery via URL parameter php/javascript

Source: Internet
Author: User

The

PHP implementation Method

is in the interface, post delivery mode, the data is transmitted as a string, and the returned data is encapsulated with JSON.

and then start a variety of tests.

Sharing the final method:

defines a crawl function:

Function http_post_data ($url,  $data _string)  {     $ch  = curl_init (
);
    curl_setopt ($ch,  curlopt_post, 1);
    curl_setopt ($ch, curlopt_url,  $url);
    curl_setopt ($ch, curlopt_postfields,  $data _string);     curl_setopt ($ch,  curlopt_httpheader, array (          ' Content-type: application/json; charset=utf-8 ',      
    ' content-length:  '  . strlen ($data _string))     );
    ob_start ();
    curl_exec ($ch);
     $return _content = ob_get_contents ();
    ob_end_clean ();
     $return _code = curl_getinfo ($ch,  curlinfo_http_code);     return array ($return _code, $Return_content); }



And then the method:

$url = "path";
$data = Array ();  Array
$data = Json_encode ($data); Convert to String
list ($return _code, $return _content) = Http_post_data ($url, $data);
$return _content = Json_decode ($return _content,1);
Var_dump ($return _content); The output returns the result.





window.open URL parameter post mode pass

A recent Web project that requires the ability to pass parameters across pages is one that needs to take the contents of the current page to the newly opened subform by passing an ID past and then reading the contents of the database in a new window. It's not much of a hassle, but if the content is stored in the database, it's just a draft state, and the user is often considered a bug. Consider a get way of passing, the need to serialize the content and then through the URL to pass, appears to be very bloated, and get the length of the delivery content is limited. Then think of the way to pass the post, the problem is that the open method can not set the request method, the general Web page post are implemented through form. If you only simulate the way the form is submitted, then the arguments in the open method that can set the properties of the form are not available. And finally find a way to do that. The combination of the two ways, the form of target set to the name of open and the same value, the browser automatically recognized the implementation of the content post to the new window.

It is interesting that the submit method directly by calling form cannot trigger the OnSubmit event, view the Help document, and manually trigger it, otherwise you will only see the page refresh without opening a new window. Only one parameter content is passed in the code, which can actually be passed multiple.
The specific code is as follows:

Function openpostwindow (url,name,data)   {      var tempForm =  Document.createelement ("form");      tempform.id= "TempForm1";       tempform.method= "POST";      tempForm.action=url;       tempform.target=name;      var hideinput = document.createelement (" Input ");      hideinput.type=" hidden ";      hideinput.name=
  "Content"     hideInput.value= data;     tempform.appendchild (hideinput);       
Tempform.attachevent ("onsubmit", function () { openwindow (name);  });     document.body.appendchild (tempform);      tempform.fireevent ("
OnSubmit ");
    tempform.submit ();     document.body.removechiLD (tempform);
    return false; } function openwindow (name)   {      window.open (' About:blank ', name, ' height=400 , width=400, top=0, left=0, toolbar=yes, menubar=yes, scrollbars=yes,  Resizable=yes,location=yes, status=yes ');  }  </script>





Call:

<a href= "javascript:void (0)," onclick= "Openpostwindow (' nowritesiteinfo.jsp ', ' nowritesiteinfo ', ' <%= Loweroffset%> '); " >
here is the call;
</A>



Note that if the Red section does not have this, it will cause the page to <jsp:include page= ""/> This page is lost, which is linked to the href and onclick coexistence issues,

The requested link is a tag with a and the href and onclick events are written on a. For link a tags, when the user clicks the mouse, the A object is triggered to execute the onclick part first, then the href.

The solution is:

directly to the OnClick event written in the href: href= "Javascript:openpostwindow (...) )"
There is also a solution: <a href= "javascript:void (0)" onclick= "Do (); >Test</a>
This ignores the href section, which is useful for passing this through the onclick, or for not avoiding a object.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.