IFrame passing in POST parameters.
仅有的幸福
仅有的幸福 2017-05-19 10:46:28
0
2
480

I have an API, such as http://XXX/test, which only supports POST requests. You need to pass parameters similar to the following to get the results.

{
    "id": "12",
    "userInfo": {
        "name": "amy",
        "age": "13"       
    },
    "map":[
        {
          "fieldName": "AA",
          "mapName": "AAA"
        },
        {
          "fieldName": "BB",
          "mapName": "BBB"
        }
    ]
}

Because this API returns an html page, it is going to be implemented using an iframe. Originally, if it was a GET request, just set the src of the iframe to this API. However, this API only supports POST requests, so I searched for it. The solution is to find that this function can be implemented in the form of a form. The code is similar to the following.

<form
      id="moodleform" target="iframe"
      method="post" action="http://www.example.com/login/index.php"
>
    <input type="hidden" name="username" value="guest"/>
    <input type="hidden" name="password" value="guest"/>
    <input type="hidden" name="testcookies" value="1"/>
</form>
<iframe name="iframe"></iframe>
<script type="text/javascript">
    document.getElementById('moodleform').submit();
</script>

But how to pass the parameters in the form here? The parameters I want to pass are not simple key-value mappings. What should I do?

仅有的幸福
仅有的幸福

reply all(2)
洪涛

Form parameter passing only supports key-value format. Ajax is an honest and practical method. If it is cross-domain and the interface does not support cross-domain, it can only be processed by the backend. If the returned HTML is troublesome, then set the HTML text as the content of the iframe. Then the dom query will be fine

阿神

I didn’t review the question carefully. Mine is also in key-value format, sorry

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template