doujuanqi2909 2015-08-11 17:09
浏览 79

如何使用getJSON从prompt var发送数据到PHP?

I Created a button that when onclick he delivering a prompt message in order The user will enter a free text. Now I need to use this free text and pass it as var input with GET method to external PHP in my system. I have tried using the getJSON method to do the following :

       '<button onclick="SendFreeMSG()">Test MSG </button>

                <p id="testMSG"></p>

                <script>
                function SendFreeMSG() {
                    var InputMessage= prompt("Please enter your Message", "Write down your message Here");

                    if (InputMessage!= null) {
                    document.getElementById("testMSG").innerHTML = "Your message is: " + InputMessage + " "  ;
                    $.getJSON("sending_msg_to_user.php?userinput=" . $InputMessage ["userinput"] .
                    }

                }
                </script>' ;

The scrpit is working fine without the getJSON row, but when I tried it with that row nothing happen.

----- Addition ---- Here is another part of my code with click button and $getJSON In this part it is working well:

                          '<button onclick="' .
                                        "if (confirm('sending message ?')) {
                             var activeValue = $(this).siblings('.all_users_active_value');" . 
                                            "var activeCaption = $(this).siblings('.all_users_active_caption');"  .
                                            "$.getJSON('sending_general_msg.php?General=" . $rowData['General'] . 
                                              "&active=' + (activeValue.html() == '1' ? '0' : '1'), " . 
                                               "function(data) { " . 
                                                "activeValue.html(data.active);" . 
                                                "activeCaption.html(data.active == 1 ? 'Active' : 'Inactive')" . 
                                            "})
                            } else {
                               alert('sending message cancelled')
                            };" .
                                            "return false;". 
                                        '"> Sending new message </button>';

I will appreciate any help with that matter

Abraham

  • 写回答

3条回答 默认 最新

  • duanchao1002 2015-08-11 17:11
    关注

    You need to use ajax to send sometime from java to a php file. below is a tutorial on how to use ajax.

    http://www.w3schools.com/ajax/

    评论

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据