0

I have these two codes that I want to combine into one, so when I click the genbtn it will add the response from the PHP file into the 'wallet' form like the function below adds the text 'bitcoin wallet after click' to it.

Instead of displaying it in an alert box like it does now, the variable in the PHP file that I want to display is $public if that helps.

I've been sitting fiddling with the code for 3 hours now with no luck.
You can check how it works now on for better understanding.

<script>
$(function () {
  $('#genbtn').one('click', function () {

    var text = $('#wallet');
    text.val(text.val() + ' bitcoin wallet after click');

  });
});
</script>

and:

<script>
$.ajax({
  url: 'addygen.php',
  success: function (response) {
    alert(response);
  }
});
</script>

html:

 <input type="text" id="wallet" maxlength="34" pattern="^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$" 
            placeholder="Your Bitcoin wallet's address"></input>
6
  • 2
    Could you please simplify your question? I am not exactly getting what you are asking. Commented Sep 24, 2017 at 19:16
  • I'll try, I want the string displayed in addygen.php to be displayed in the 'wallet' form when you click the 'genbtn'. Commented Sep 24, 2017 at 19:48
  • You have to show what is #wallet. Post your HTML. Commented Sep 24, 2017 at 20:56
  • Just posted it. Commented Sep 24, 2017 at 21:11
  • the output of addygen.php is 1KiJnydDYR9ZHfxNWrfGUtUKDJgVkTo4Qm (string like this)... That doesn't look like what you wish to be displayed. Commented Sep 24, 2017 at 21:32

2 Answers 2

2

So, here where we are:

  1. When I used the following code with a local phpPage.php, it works fine
  2. When I put the url: 'http://www.ubit.ca/addygen.php' the developer tool showed me the following error:

the connexion used to get resources not encrypted

So I think that he problem is whith your permission to acces to the http://www.ubit.ca/addygen.php file.

$.ajax({
    url: 'http://www.ubit.ca/addygen.php',
    ifModified: true,
    dataType: 'text',
    success: function(data){
        $("#wallet")
    },
    error:function(){
        alert("error");
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="wallet" maxlength="34" pattern="^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$" placeholder="Your Bitcoin wallet's address"/>

Sign up to request clarification or add additional context in comments.

6 Comments

I've tried it before and it doesn't work, I just need the response added to the form. So I removed the "+ ' bitcoin wallet after click'" and its still doesnt work.
@NipBoss which form ? please can you add you HTML code ?! I need to know where you exactely want to put this response
Ok, one moment.
@NipBoss I edited my answer, try my solution on your local machine & see if the code is working, for me it works very fine. GOOD LUCK
Thank you very much, you basically had it. I just modified it a bit.
|
0

here's a code snippet of the solution:

<script>
$(function() {
    $('#genbtn').one('click', function() {
        $.ajax({
            url: 'addygen.php',
            success: function(response) {
                var text = $('#wallet');
                text.val(response);
            }
        });
    });
});
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.