0

I have made a Script sendsms.php which executes and sends SMS with HTTP API. I call sendsms.php with a Java script (Button) and get back results in a text input window.

When I press my Java Button the phone number is automatically sent to sendsms.php and it executes. Below in my CODE you can see how the #phone is sent (with Java) and how its retrieved by sendsms.php

My question is: Now I want add and SEND #nick_name together with #phone. How should I do that?

My Jave Button:

<script type="text/javascript">
    $(document).ready(function() {
        $('.smsbutton').click(function() {
            var val = $('#phone').val();
            $.get('http://mydomain.com/sendsms.php', {phone: val}, function(data) {            
                result = $.parseJSON(data);
                $("input[name='avaresultsms']").val(result.avaresultsms);
            });
        });
    });
    </script>
<br />
<input type="text" name="avaresultsms" value="" style="width: 370px;" readonly="readonly" />
<input id="smsbutton" name="smsbutton" type="button" class="smsbutton" value="SEND SMS">

And here is sendsms.php:

<?php

$phone = $_GET['phone'];
$smstophone = str_replace("+", "", $phone);

$sendapi = 'http://sms.com/api.php=sendsms&user=MYUSERNAME&password=MYPASS&&from=Escort%20Home&to='.$smstophone.'&text=Hello%20'.$nick_name.'%20Test1%20test2';
$smsrsult = file_get_contents($sendapi);
$result['avaresultsms'] = $smsrsult;
echo json_encode($result);
?>

As you can see I use var val = $('#phone').val(); in Java Button so with sendsms.php I can get it with: $phone = $_GET['phone'];

But now I also want to get $nick_name = $_GET['nick_name']; What should I add to Java script?

Thank you very much for your help.

THIS WORKED FOR ME:

var nickname = $('#nick_name').val();
$.get('http://mydomain.com/sendsms.php', {phone: val, nick_name: nickname}, function(data) {

2 Answers 2

1

try something like this

             var val = $('#phone').val();
             var nick_name_val = 'sample name';
             $.get('http://mydomain.com/sendsms.php', {phone: val,nick_name: nick_name_val}, function(data) {            
                 result = $.parseJSON(data);
                 $("input[name='avaresultsms']").val(result.avaresultsms);
             });
Sign up to request clarification or add additional context in comments.

2 Comments

$phone and $nick_name is previously defined as variables in PHP. So I get #phone working this way. Cant I do something like $('#nick_name') ?
it variable name , you can keep what you want
0

Just add the nick name like how you got phone and add it to the object.

var nickname = $('#nickname');
$.get('http://mydomain.com/sendsms.php', {phone: val, nick_name: nickname}, function(data)

1 Comment

I will try now, should it be: var nickname = $('#nick_name');?

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.