简体   繁体   中英

How to implement the equivalent of the Win32 function MessageBox in PHP/JavaScript?

I already have a working PHP function that outputs a JQuery UI dialog with almost the same prototype ( MessageBox($text, $caption, $flags) where $flags is an unsigned int (flags can be passed like that: MB_OK | MB_ICONWARNING ).

This is working perfectly. My problem is how to get values back from the popup? It can have OK, CANCEL, RETRY, etc, buttons, and I would like to know if its possible to know which button has been pressed client-side from the PHP. Typically, the function should return 1 if OK has been pressed, 2 if CANCEL has been pressed, etc.

I've looked at AJAX and regular form posting, but it seems impossible to just do:

$userInput = MessageBox("Would you like to delete this line?", "WARNING", MB_OKCANCEL | MB_ICONWARNING); 

(See here for the Win32 function)

I don't know how work Win32 function, but I think in javascript it maybe this:

if (confirm('Would you like to delete this line?')) {
    // Delete it!
} else {
    // Do something!
}

AJAX and regular form posting are your only options, really. That's how the client talks to the server on the web. You can't really "show a dialog" in PHP - you're doing it in JavaScript (via jQuery). JavaScript/jQuery code will have to handle which button was clicked and communicate this back to PHP. Answering in more detail isn't really possible in a question/answer format. I suggest giving AJAX a try and see if you come up with a more specific question we can answer instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM