請問如何讓Main()用到commandajax()
並在commandajax() 裡,可以使用savecmd和 catcmd兩個指令呢?
//初始載入畫面
function Main()
{
//讀取floag資料
alert("Main:");
var savecmd = "echo -n \"save"+"\" > /app/Web/cgi-bin/login.txt";
var catcmd = "cat /app/Web/cgi-bin/login.txt";
var floag = funtion(command, isMsg);
function commandajax(command, isMsg)
{
var ReturnString = "";
var ipAddress = location.protocol+"//"+location.hostname+"/cgi-bin/";
var URLs = ipAddress + "PProduceXml.php";
alert(2);
// var savecmd = "echo -n \"save"+"\" > /app/Web/cgi-bin/login.txt";
// var catcmd = "cat /app/Web/cgi-bin/login.txt";
//alert("Action=TransmissionStart&submitString="+(savecmd,catcmd));
$.ajax(
{
url: URLs,
data:"Action=TransmissionStart&submitString="+command,
type:"GET",
async: false,
cache:false,
success: function(msg)
{
alert("msg:"+msg);
if(isMsg == true)
{
ReturnString = msg;
}
},
error:function(xhr, ajaxOptions, thrownError)
{
}
});
return ReturnString;
}
先跟你確定你的程式要在什麼環境下跑,瀏覽器端或是伺服器端。
在瀏覽器端跑shell script是不可能的。
在伺服器端,如果是在node.js環境,通常會直接用它的http client而不是jquery。
這麼堅持...那你用 ; 把兩個命令分隔開試試看, 例如
cat xxxxx ; echo xxxxx > xxx
//-------------------------------------------
//寫入save字串到login.txt
function savewrite()
{
//write
var ReturnString = "";
var ipAddress = location.protocol+"//"+location.hostname+"/cgi-bin/";
var URLs = ipAddress + "PProduceXml.php";
var ss = "echo -n \"save"+"\" > /app/Web/cgi-bin/login.txt";
//alert("write:"+ss);
//var URLs = ipAddress + "Command.cgi";
$.ajax(
{
url: URLs,
data:"Action=TransmissionStart&submitString="+ss,
type:"GET",
async: false,
cache:false,
success: function(msg)
{
//alert("msg:"+msg);
},
error:function(xhr, ajaxOptions, thrownError)
{
//alert("xhr:"+xhr+" ajaxOptions:"+ajaxOptions+" thrownError:"+thrownError);
}
});
return ReturnString;
}
//讀取login.txt
function loginread()
{
var ReturnString = "";
var ipAddress = location.protocol+"//"+location.hostname+"/cgi-bin/";
var URLs = ipAddress + "PProduceXml.php";
var ss = "cat /app/Web/cgi-bin/login.txt";
$.ajax(
{
url: URLs,
data:"Action=TransmissionStart&submitString="+ss,
type:"GET",
async: false,
cache:false,
success: function(msg)
{
alert("msg:"+msg);
ReturnString = msg;
},
error:function(xhr, ajaxOptions, thrownError)
{
//alert("xhr:"+xhr+" ajaxOptions:"+ajaxOptions+" thrownError:"+thrownError);
}
});
return ReturnString;
}
//初始載入畫面
function Main()
{
//讀取floag資料
var floag = loginread();
// var floag = loginread();
//alert("floag"+floag);
//依照floag內容讀取不同區塊
if(floag == "login")//讀取初始值
{
ReadGroup();
}
else if(floag == "save")//讀取修改值
{
ReadGroup1();
}
}
其實原本是寫function savewrite() function loginread()兩個函數,如上圖
但要精簡化,寫成一個function