最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

call php page under Javascript function - Stack Overflow

programmeradmin4浏览0评论

Is it Possible to call php page under Javascript function? I have an javascript function and I want to call php page if someone press okk

Here is my code so far

function show_confirm()
{
var r=confirm("Do You Really want to Refund money! Press ok to Continue ");
if (r==true)
  {
  alert("You pressed OK!");
  return true;
  }
else
  {
  alert("You pressed Cancel!");
  }
}

and this Js function i m using here

<td align="center"><input name="Refund" onclick="show_confirm()" type="submit" value="Refund" /></td>

now i want if user press okk then call other php page ...

Is it Possible to call php page under Javascript function? I have an javascript function and I want to call php page if someone press okk

Here is my code so far

function show_confirm()
{
var r=confirm("Do You Really want to Refund money! Press ok to Continue ");
if (r==true)
  {
  alert("You pressed OK!");
  return true;
  }
else
  {
  alert("You pressed Cancel!");
  }
}

and this Js function i m using here

<td align="center"><input name="Refund" onclick="show_confirm()" type="submit" value="Refund" /></td>

now i want if user press okk then call other php page ...

Share Improve this question edited Dec 18, 2012 at 17:11 hakre 198k55 gold badges446 silver badges854 bronze badges asked Aug 23, 2011 at 6:22 JohnJohn 1751 gold badge1 silver badge12 bronze badges 4
  • 1 Are you redirecting users to another page if they pressed ok button? – dcai Commented Aug 23, 2011 at 6:25
  • you want to redirect to that page or fetch data from it? – Mithun Satheesh Commented Aug 23, 2011 at 6:26
  • @mithunsatheesh:)only redirect – John Commented Aug 23, 2011 at 6:27
  • pageresource./jscript/jredir.htm – Mithun Satheesh Commented Aug 23, 2011 at 6:30
Add a ment  | 

5 Answers 5

Reset to default 8

if you want to redirect to a page:yourphppage.php if the user pressed ok.

 function show_confirm()
 {
      var r=confirm("Do You Really want to Refund money! Press ok to Continue ");
      if (r==true)
        {
        window.location="yourphppage.php";
        return true;
        }
           else
        {
        alert("You pressed Cancel!");
        }
 }

If you are looking for page direction:

window.location="index.php";

There are plenty other methods to redirect: http://grizzlyweb./webmaster/javascripts/redirection.asp

Place this where you want your redirect to happen:

location.href = "newpage.php";

Checkout
http://www.w3schools./xml/xml_http.asp
Then have a look at
http://mootools/docs/core/Request/Request
Any of the JS libraries prototype Jquery etc. have a wrapper to make requests and your life easier.
Then just have a button and set its onClick to be the request call to the server and listen for the response.


Some tips you can append data to the request URL to pass your PHP script variables. Checkout
http://www.w3schools./tags/ref_urlencode.asp

If you only want to redirect the page to the "refund" page without using AJAX you can do something along the lines of the following:

(assumes $transaction_id variable is the id number you are looking to refund)

HTML Lines:

    <td align="center">
    <input name="Refund" onclick="show_confirm(<?php echo $transaction_id ?>)" type="submit" value="Refund" />
    </td>

Javascript lines:

    function show_confirm(transaction_id) 
    { 
        var r = confirm("Do You Really want to Refund money! Press ok to Continue "); 
        if (r == true)   
        {   
            alert("You pressed OK!");  
            location.href = "refund.php?transaction_id="+transaction_id; 
            return true;   
        } 
        else   
        {   
            alert("You pressed Cancel!");   
        } 
    } 
发布评论

评论列表(0)

  1. 暂无评论