简体   繁体   中英

Google Analytics Dashboard AJAX Function Does Not get values

I have used the following function to pass certain data to an ASP.Net web service.

function setJsonSer() {
    $.ajax({
        url: "/APIWebService.asmx/AnalyticsDataShowWithPost",
        type: 'POST',
        data: {
            Email: 'clientlink@russell.com',
            Password: 'russell1234',
            URL: getVaria()
        },
        success: function(data) {
            alert("success alert    " + data);
            var sTitle = $(data).find('string').text();
            alert("sTitle Alert " + sTitle);
            alert("The data string    " + data);
        },
        error: function(xhr, textStatus, errorThrown) {
            alert('error in simple method');
            alert(textStatus);
            alert(errorThrown);
        }
    });
    $.ajax({
        url: "/APIWebService.asmx/GetMessage",
        type: 'POST',
        data: {
            Email: 'clientlink@russell.com',
            Password: 'russell1234',
            URL: getVaria()
        },
        success: function(data) {
            alert(success);
            var sTitle = $(data).find('string').text();
            alert(sTitle);
            alert(data);
        },
        error: function(xhr, textStatus, errorThrown) {
            alert('error in simple method');
            alert(textStatus);
            alert(errorThrown);
        }
    });
}    

I have alert the.

data: {
    Email: 'clientlink@russell.com',
    Password: 'russell1234',
    URL: getVaria()
}, 

However the alert is [object document] . I think that should the alert not be. So you guys have any ideas, opinions about this?

Thanks & regards, Chiranthaka

You're constructing data wrong.

Try

data: {
    'Email': 'clientlink@russell.com',
    'Password': 'russell1234',
    'URL': getVaria()
} 

You might also want to use JSON.stringify(data) per the comment if you want to send as JSON formatted data.

EDIT

Try creating a new var - called myData - above your $.ajax command:

var myData = {'Email': 'clientlink@russell.com', 'Password': 'russell1234', 'URL': getVaria() };

The in your ajax command use this line for data:

data:JSON.stringify(myData);

try this one

function setJsonSer() {
    formData = {
        Email: 'clientlink@russell.com',
        Password: 'russell1234',
        URL: getVaria()
    };
    $.ajax({
        url: "/APIWebService.asmx/AnalyticsDataShowWithPost",
        type: 'POST',
        data: formData,
        complete: function(data) {
            alert(JSON.stringify(data));
        }
    });
    $.ajax({
        url: "/APIWebService.asmx/GetMessage",
        type: 'POST',
        data: formData,
        complete: function(data) {
            alert(JSON.stringify(data));
        }
    });
}

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