php讀取js變數的ajax代碼

來源:互聯網
上載者:User
如題,網上找了很多代碼看,看的好亂,自己嘗試了下也沒搞定。要求非常簡單,只是想php從js中讀取一個形參而已,也不需要js再接收什麼php的傳回值,部分代碼如下,求哪位大神幫忙寫個,3q
$device = $_POST['phone'];
function count_num()
{
echo $device;
}
?>


回複討論(解決方案)

check.php

  
不過你沒有接收 check.php 處理結果的代碼,沒法看到

你可以
$.post("check.php", { phone:device }, function(d) {alert(d)} );
這樣看一下

也可以
file_put_contents('test.txt', $_POST['phone']);
在 test.txt 中看一下

      $device = $_POST['phone'];

我以為這樣就能接收到了,結果提示Notice: Undefined index: phone。
上面寫的php和js就是在check.php檔案中的,我只是想用php讀取js函數ShowNumber()的形成那,然後再根據讀取到的形參在資料庫中查詢滿足的值。只是想獲得一個形參,傳回值什麼的都沒。
您給我的$.post("check.php", { phone:device }, function(d) {alert(d)} );我試了下,沒反應

JQ類引了沒了?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.