简体   繁体   中英

Convert JavaScript Popup to Alert Box

I have the following code in a PHP page. The code below was converted from a popup window to open in the same window. I need to convert it so that instead of going to a new page, it outputs the request.php result as a standard Javascript alert box. I have seen it done before with this same type of setup, I just haven't been able to get mine to work.

The server is running PHP 5.1.6 and cannot be updated by me (Provided by university), so certain PHP functions are unavailable. I'm not whether or not that is helpful information.

The page returns:

Request Status
Thank you for your request, it has been added to the queue.

or:

Request Status
You can only submit a request once per 300 seconds.

The current PHP code is below:

$ret = "<a href=\ "#\" onClick=\ "javascript:window.open('request.php?id=".$params[ 'id']. "','_self','scrollbars=yes,status=no,menubar=no,location=no,resizeable=yes,height=200,width=400'); return false;\"><img src=\"";

I got this (kind of) working by changing the line

$ret = "<a href=\ "#\" onClick=\ "javascript:window.open('request.php?id=".$params[ 'id']. "','_self','scrollbars=yes,status=no,menubar=no,location=no,resizeable=yes,height=200,width=400'); return false;\"><img src=\"";

to

$ret = "<a href=\"#\" onClick=\"javascript:jQuery.get('request.php?id=".$params['id']."', function(data) { alert(data); });\"><img src=\"";

however, this dumps the entire page (including html tags) to the alert box.

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