簡體   English   中英

使用JavaScript將mysql查詢+ http請求提交到SMS網關

[英]Submit, mysql query + http request to a SMS gateway using JavaScript

我收到一些數據到我的Confirm.php文件中。 Confirm.php文件包含以下代碼。 我被javascript困住了,將不勝感激所有輸入和幫助。

我希望我的JavaScript可以執行以下操作:
當用戶單擊提交的“批准和SMS”按鈕時,查詢將發送到我的數據庫(包含客戶,任務和用戶數據),同時將HTTP請求發送到SMS網關。 用戶單擊“批准和SMS”按鈕后,將彈出一個警報框,當用戶在警報框中單擊“確定”時,我要將用戶重定向到我的index.php。

注意 :我不需要關於實際的mysql查詢的建議,只需關於如何使魔術觸發器發送帶有javascript的查詢+ http請求( 它不一定是純javascript的建議,歡迎所有解決方案,只要他們解決了我的問題)。

確認PHP

<?php
    //check session to get customer
    if(!isset($_SESSION['customer'])) {
        die('$'."_SESSION['customer'] Session ended");
    } else {
        $customer = $_SESSION['customer'];
        echo $customer;
    }
?>
<?php
  if(isset($_POST['submit'])) {
 // Fetching variables of the form which travels in URL 
    $tasks = $_POST['tasks'];
    $user = $_POST['user'];
 ?>

SMS API的東西

<?php
//Create $sms_url to send sms to customer
// The necessary variables
$sms_message = ("this is a text");
$sms_url = "http://the.domain/sms/";
$sms_url .= "?message=" . urlencode($sms_message); //messages
$sms_url .= "&recipient=$customer"; // Recipient
$sms_url .= "&from=" . urlencode("name company."); // Sendername
//echo $sms_url;
?>

一些HTML

<form id="sms_insert_data" action="???" method="POST">
<input class="submit" name="showWordCard" type="submit" value="Approve & SMS"></input>
</form>

JAVASCRIPT

$(document).ready(function(){
 $('.submit').click(function(){
  var foo = alert('Card created and SMS sent to: <?php echo json_encode($customer); ?>');
  window.location = "..//index.php"
  });
});

您可以使用jQuery ajax將http請求發送到php腳本和/或您的sms網關。 http://api.jquery.com/jquery.ajax/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM