Respond Request for publication, how to submit a form

I am trying to achieve a similar thing in React Native of any idea how I can do this

<form action="http://example.com/some-url-end-point" method="POST">
  <input type="hidden" name="q" value="a">
</form>

Is there any way to do something like this in React Native. I can do this in a web application. But in the reaction, native window.documentdoes not exist. Therefore, I cannot present the form dynamically or in any way.

Basically, I send some data to a third-party payment gateway with data from the POST method. Any idea how I can achieve this in React Native?

Edit: I need a solution that changes when sending a web view that changes the location of the browser and sends data to this place in the formatpost

A similar question I found for implementing Javascript is a request to send JavaScript how to submit a form. I need to achieve something similar in my native reaction.

+6
source share
3 answers

Since what you are trying to do is actually create a web form and redirect after that, why not create your form using HTML? You can do this using WebView. It sourceprop accepts HTML directly or a remote source, and thus you can get the desired result.

+4
source

React Native has no equivalent in html form.

. React Native fetch, - Axios XMLHttpRequest.

Networking React Native.

UI , , .

+4

This is my solution for doing a "POST". I am new to responding, so feel free to give me constructive criticism.

    var params   = {                
        userName: 'BILLY BOB',
        password: 'password',
    };            

    for (var k in params) {
        var encodedKey = encodeURIComponent(k);
        var encodedValue = encodeURIComponent(params[k]);
        formBody.push(encodedKey + "=" + encodedValue);
    }

    formBody = formBody.join("&");


    var request = {
        method: 'POST',
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        'Another-Header' : 'any info i want to pass',
        body: formBody
    };


var URL_Register = 'http://myURL';   
    fetch(URL_Register, request)
    .then(
        function(response){
            if(response.status != 200)
            {
                return;
            }
            response.json()
            .then(function(data) {
                   //can access JSON data returned if any
            }.bind(this));
        }.bind(this)            
    )
    .catch(function(err){
        console.log('Fetch Error', err);
    })    
};
+1
source

All Articles