Jump to content

How send and receive variable / php


bogdann77

Recommended Posts

i have the file 1.html:

.....
<script src="/libs/jquery-1.3.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
    var url0='{$url0}';
    var url1='{$url1}';
    var url2='{$url2}';
    var url3='{$url3}';
    var OPEN_ON = false;
    openurls= function(){
    if(confirm('Opens all?') && OPEN_ON == false){
                    OPEN_ON = true;
    $.ajax({
    type: "POST",
    url: "a1.php",
    data: { url0: url0, url1: url1, url2: url2, url3: url3 },
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {
      window.open(url0);
      window.open(url1);
      window.open(url2);
      window.open(url3);
alert(msg);
    },
    error: function(msg) {
alert(msg);
    }
})

                 setTimeout("location.reload(true);",3000) 

                    OPEN_ON = false
                }
                return false

    }

........
<strong><br><a href="#" onclick="openurls();return false;">Open all </a></strong>

 

The code from a1.php is

<?php
$url2=$_POST['url2']
    if ($url2=="http://www.yahoo.com"){
    $url2="http://google.com";
    $return = 'true';
    };
    $url3=$_POST['url3']
    if ($url3=="http://www.yahoo.com"){
    $url3="http://google.com";
    $return = 'true';
    };

    ?>

 

After you press the link "Open All" write "[object XMLHttpRequest]" (error).

Can anyone help me to send the four variables and after verification of a1.php, to send them back.

I am a novice with AJAX.

Link to comment
https://forums.phpfreaks.com/topic/218715-how-send-and-receive-variable-php/
Share on other sites

According to the jQuery API:

 

error(XMLHttpRequest, textStatus, errorThrown)

A function to be called if the request fails. The function is passed three arguments: The XMLHttpRequest object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "notmodified" and "parsererror". This is an Ajax Event.

and

 

success(data, textStatus, XMLHttpRequest)

A function to be called if the request succeeds. The function gets passed three arguments: The data returned from the server, formatted according to the 'dataType' parameter; a string describing the status; and the XMLHttpRequest object (available as of jQuery 1.4). This is an Ajax Event.

 

Your error and success functions are only accepting 1 parameter each.

 

Especially for your error function, the first parameter is the XMLHTTPRequest object, resulting in the alert box showing "[object XMLHttpRequest]"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.