jQuery, ajax POST method success returns: Undefined

Sarath Kumar

my script code:

$('#btnSave').click(function() {
    var pageUrl = '<%= ResolveUrl("~/TestPage.aspx/SystemEdit")%>';
    var ip = $('#editIP').text();
    var loc = $('#txtBay').val();
    var team = $('#txtTeam').val();
    var port = $('#txtPort').val();
    var xcel = "", office = "", moni = "";                                   
    var parameter={ "ip": ip, "loc": loc, "team": team, "port": port, "excel": xcel, "office": office, "monitor": moni}

    $.ajax({
        type: 'POST',
        url: pageUrl,
        data: JSON.stringify(parameter),
        contentType: 'json',
        success: function(data) {
            alert(data);
        },
        error: function(data,success,error) {
            alert("Error:" +error);
        }
    });           
});

my code behind c# code is:

[WebMethod]
public static string SystemEdit(string ip, string loc,string team, string port, string excel,string office, string monitor)
{
    return "The Current Time is: "+ DateTime.Now.ToString();
}

my page name is : TestPage.aspx

While clicking the save button I'm getting 'undefined'. I'm not getting the current time from code behind c#.

Neel

You need to return json result as below:

return JsonConvert.SerializeObject("The Current Time is: "+ DateTime.Now.ToString());

also put below attribute above method:

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]

And as you specified json format you should write:

 contentType: "application/json; charset=utf-8",

By the way you should use a Webservice here!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jQuery AJAX Post Success will not update div, displays partial view

From Dev

jQuery, Convert $.ajax method to $.post

From Dev

jquery ajax post data undefined

From Dev

Why is the URL undefined (After JQuery Ajax Post)

From Dev

jQuery AJAX method and Post method

From Dev

formData object sent with jQuery ajax to server returns empty array on success

From Dev

ajax post call returning undefined success message

From Dev

how to call spring controller in jquery ajax success method

From Dev

jQuery's .children() method returns 'undefined'?

From Dev

Rejecting A jQuery Promise In A $.ajax Success Method

From Dev

Undefined Index PHP Ajax jquery post

From Dev

Jquery Ajax cross Domain returns success as status in error function

From Dev

Cross Domain jQuery Ajax Response returns Undefined

From Dev

jQuery - $.ajax returns other dataFormat as $post

From Dev

JQuery .ajax() function call not working, but success method runs

From Dev

Jquery AJAX responseText returns undefined

From Dev

undefined return ajax success

From Dev

jQuery Ajax and POST method in PHP

From Dev

jquery ajax post data undefined

From Dev

Why is the URL undefined (After JQuery Ajax Post)

From Dev

jQuery returns undefined while filtering AJAX response

From Dev

Jquery Ajax returns Undefined on accessing specific column

From Dev

How can I use an if statement in a $.jQuery ajax post's success:?

From Dev

formData object sent with jQuery ajax to server returns empty array on success

From Dev

how to call spring controller in jquery ajax success method

From Dev

Javascript/jquery AJAX post WITH VARS function returns undefined

From Dev

Jquery post method and redirect after success

From Dev

Ajax File upload in Jquery returns success as result

From Dev

Jquery: Ajax POST request / success event not fired

Related Related

  1. 1

    jQuery AJAX Post Success will not update div, displays partial view

  2. 2

    jQuery, Convert $.ajax method to $.post

  3. 3

    jquery ajax post data undefined

  4. 4

    Why is the URL undefined (After JQuery Ajax Post)

  5. 5

    jQuery AJAX method and Post method

  6. 6

    formData object sent with jQuery ajax to server returns empty array on success

  7. 7

    ajax post call returning undefined success message

  8. 8

    how to call spring controller in jquery ajax success method

  9. 9

    jQuery's .children() method returns 'undefined'?

  10. 10

    Rejecting A jQuery Promise In A $.ajax Success Method

  11. 11

    Undefined Index PHP Ajax jquery post

  12. 12

    Jquery Ajax cross Domain returns success as status in error function

  13. 13

    Cross Domain jQuery Ajax Response returns Undefined

  14. 14

    jQuery - $.ajax returns other dataFormat as $post

  15. 15

    JQuery .ajax() function call not working, but success method runs

  16. 16

    Jquery AJAX responseText returns undefined

  17. 17

    undefined return ajax success

  18. 18

    jQuery Ajax and POST method in PHP

  19. 19

    jquery ajax post data undefined

  20. 20

    Why is the URL undefined (After JQuery Ajax Post)

  21. 21

    jQuery returns undefined while filtering AJAX response

  22. 22

    Jquery Ajax returns Undefined on accessing specific column

  23. 23

    How can I use an if statement in a $.jQuery ajax post's success:?

  24. 24

    formData object sent with jQuery ajax to server returns empty array on success

  25. 25

    how to call spring controller in jquery ajax success method

  26. 26

    Javascript/jquery AJAX post WITH VARS function returns undefined

  27. 27

    Jquery post method and redirect after success

  28. 28

    Ajax File upload in Jquery returns success as result

  29. 29

    Jquery: Ajax POST request / success event not fired

HotTag

Archive