English 中文(简体)
• 通过 Java字向服务器发送PHP?
原标题:Call PHP on server via Javascript?

I am attempting to make a dead simple webpage that does things when I click a button.

我试图使用Javascript,因此我不必重载主页或任何东西。

因此,我想有一个说“down倒”的纽子,我只是想 shut倒。 将在我点击时关闭服务器。

现在我一直在找一个小时,可以找到一个简单的例子。 某人能否举出一个非常简单的例子,或者说一个链接?

致谢:

EDIT: Okay so here s my pitiful attempt.. it doesn t work.. any tips?

<html>
<head>
<title>Control Page</title>
</head>

<body>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript">
/*************************************
JQUERY EXAMPLE
*************************************/
$( #mysubmit ).click(){
    var jqueryXHR = $.ajax({
         type :  POST ,
         url :  http://localhost/killIE.php ,
         dataType :  json 
       });
    }
}
</script>

<input type="submit" name="mysubmit" value="Click!" />


</body>
</html>
最佳回答

Yep - technology called called AJAX. You can either write it in raw javascript or use ready made libraries. The most popular JS library nowadays (subjectively) is jQuery, I ll use it in my example.

NOTE:这将引发您的关闭。 服务器上的硬拷贝没有上载。 但是,在你关闭服务器之后,你显然能够提出网络要求:

/*************************************
JQUERY EXAMPLE
*************************************/
$( #myShutdownButton ).click(){
    var jqueryXHR = $.ajax({
         type :  GET ,
         url :  http://someServer.com/shutDown.php ,
         data : { shutdownServer :  yes },//optional
         dataType :  json 
       });
    }
}

P.S.,我假定,你知道,你必须首先在你的html档案馆上装饰图书馆,例如:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>

之后,将这种分类法置于文字标签内:

<script>
...that jQuery code...
</script>

www.un.org/Depts/DGACM/index_spanish.htm 内容提要——完整的文字版

<html>
<head>
<title>Control Page</title>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" type="text/javascript"></script>
    <script>
        //we need document.ready call to make sure that DOM loaded before we try to bind anything
        $(document).ready(function() {
            //Here we bind click event
            $( #mysubmit ).bind( click , function(e){e.preventDefault();
                //This is what happens on click - we send AJAX request
                var jqueryXHR = $.ajax({
                     type :  POST ,
                     url :  http://localhost/killIE.php ,
                     dataType :  json 
                   });
                //And when AJAX requests complete(succeeded or failed) - we update text
                jqueryXHR.complete(function(){  
                    $( span#result ).html( Oh no!!! the End is neearh! erver is shutting DoWn. )
                });
            })
        });
    </script>
</head>
<body>
    <input type="submit" id="mysubmit" value="Kill da server!" style = "margin-left:100px; margin-top:100px;" />
    <br/>
    <br/>
    <br/>
    <span id = "result">Not clicked yet - good!</span>

</body>
</html>
问题回答

如果你想通过javascript来做这件事,那么我建议你使用jQuery ,但只能用

Hope this helps.

为什么不只打开营地档案? 如果你真的想要获得活力,我相信你能够把它装上一种模式。 我认为,不管“shutDown.php”是什么,它只是花在页上。 因此,你怎么说,这大概不重要。

<html>
 <head>
 <script type="text/javascript">
 function open_win()
 {
 window.open("http://www.url.com/shutDown.php")
 }
 </script>
 </head>
 <body>

<input type=button value="Shut Down" onclick="open_win()" />

</body>
 </html>

Here is a quick tutorial that can teach you how to do this: http://aleembawany.com/2005/09/01/ajax-instant-tutorial

尽管我不得不说,拥有一个公开的、有权关闭你的服务器的网址是不安全的。 如果错失者被 hold留......

你重新寻找的东西被称为阿马斯特劳。 Search!

do one thing.. That when you click on to the shutdownm button just open this page on next page dont open in same page and execute it.. And close the new page after some period.. So u dont need to reload the page.. Hope this work.. Try this..





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签