Shoutbox

Open page in the background - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Open page in the background (/showthread.php?tid=84848)

Open page in the background by SnuZZer on 07-15-2008 at 06:16 PM

Hey.

I'll start making a quote from the thread, I posted earlier today:

quote:
I'm making an website for quotes for my IRC channel. The idea is, that people can send in quotes, but I do of course not want everything quoted on the site, so my idea is to combine it with MSG Plus! When people have added a quote on the website, it shall be accepted or declined in MSG Plus!

My idea is to make a list control where all quotes appears and when I press the accept/decline button a webpage should popup where I'll run some PHP codes to update the MySQL database.

As you can see, I've made som of the quote italic. I said, I want the webpage to popup, but that's not really that sensible. It makes the script have no sense at all.
Instead I'ld like the webpage to more or less one in the background. No browser should popup.

The page was ment to contain a PHP script, which connects to and updates my MySQL database. I guess that's not possible, so instead I'm "linking" to a page on my server.

Can this be done a smarter way?

Thanks in advance.
Simon Støvring
RE: Open page in the background by matty on 07-15-2008 at 06:21 PM

Are you using POST or GET in your PHP script to read the quote you are sending to the database?


RE: RE: Open page in the background by SnuZZer on 07-15-2008 at 06:39 PM

quote:
Originally posted by matty
Are you using POST or GET in your PHP script to read the quote you are sending to the database?

Well, I could use both, what do you have in mind?

I guess GET is the easiest way in this case.
RE: Open page in the background by matty on 07-16-2008 at 12:33 AM

Credit -dt-
-dt-'s reply to Tips

code:
var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("POST", "http://localhost/index.php", true);

xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) {
        Debug.Trace(xmlhttp.responseText);
    }
}
xmlhttp.send('quote=this is a quote');

RE: Open page in the background by SnuZZer on 07-16-2008 at 11:12 AM

Thanks, but I don't think, I'm using the script the right way.

quote:
function OnWinEvent_CtrlClicked(Wnd, CtrlId)
{
    switch(CtrlId)
    {   
        case "BtnAccept":
        {
            for(var i=0; i < Wnd.LstView_GetCount("ListView"); i++)
            {
                  if(Wnd.LstView_GetSelectedState("ListView", i) === true)
                  {
                      var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    xmlhttp.open("POST", "http://www.snuzzer.dk/wowforge/admin-msgplus.php", true);
                   
                    xmlhttp.onreadystatechange=function()
                    {
                         if (xmlhttp.readyState==4)
                         {
                               Debug.Trace(xmlhttp.responseText);
                          }
                    }
                   
                    xmlhttp.send("quote=32");
                         break;
                  }
            }
            break;
        }
    }
}

I guess the xmlhttp.onreadystatechange=function() function is only for the debug trace.

But what is xmlhttp.send("quote=32"); for?

I will be able to use the get function by changing the URL in the following line:
quote:
xmlhttp.open("POST", "http://www.snuzzer.dk/wowforge/admin-msgplus.php", true);

To something smilar to:
quote:
xmlhttp.open("POST", "http://www.snuzzer.dk/wowforge/admin-msgplus.php?quote=32", true);

RE: Open page in the background by Ezra on 07-16-2008 at 01:36 PM

now you changed it from POST to GET, the send('quote=32') is for the POST variables, adding the variables in the URL string is for GET.

And if the script doesn't return anything then you won't use the onreadystate function indeed, maybe only to know if you sent the quote correctly. If it does return any data, then the data will be available in this function.


RE: Open page in the background by SnuZZer on 07-16-2008 at 02:28 PM

Hm, okay. I couldn't seem to get POST work right, but it should be the same, if I use GET or POST in this situation, I think.


RE: Open page in the background by matty on 07-16-2008 at 02:46 PM

Javascript:

code:
function OnWinEvent_CtrlClicked(Wnd, CtrlId){
    switch(CtrlId) {
        case 'BtnAccept': {
            for(var i=0; i < Wnd.LstView_GetCount('ListView'); i++) {
                if(Wnd.LstView_GetSelectedState('ListView', i) === true) {
                    oSendData('quote=this is a quote');
                }
            }
            break;
    }
}

function oSendData (sData) {
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.open('POST', 'http://www.snuzzer.dk/wowforge/admin-msgplus.php', true);

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
            Debug.Trace(xmlhttp.responseText);
        }
    }
    xmlhttp.send(sData);
}

PHP:
code:
<? echo $_POST['quote']; ?>

Also your code appears to be messed. You have one to many breaks; look at the code.

[Image: v6sqvqwd-code.jpg]