Sunday, 15 September 2013

json - Receive Undefined in Ajax success/complete function -



json - Receive Undefined in Ajax success/complete function -

i using jquery 1.11.1. code below , receive "undefined" in response ajax call. can please help me find solution?

$(document).ready(function () { $("#txtsearch").keyup(function (e) { e.preventdefault(); var x = $("#txtsearch").val(); // alert(x); $.ajax({ type: "post", url: '@url.action("search","officelocation")', datatype: "application/json; charset=utf-8", data: json.stringify({"location":x}), // datatype: "json", complete: function (data) { var table = "<table class='table'>"; $.each(data, function (index, value) { table += "<tr><td>" + value.name + "</td></tr>"; }); table += "</table>"; alert(table); $("#mydata").html(table); } }); }); });

and related controller:

public actionresult search(string location) { var locationviewmodel = new list<officeassignment>(); locationviewmodel = db.officeassignments.where(x => x.name.startswith(location)).tolist(); homecoming json(locationviewmodel,jsonrequestbehavior.allowget); }

when utilize success instead of complete, not nail success function!

that because finish runs after success , error callbacks. think you're getting error, seek grab , see receives.

how url '@url.action("search","officelocation")' computed in javascript? doesn't seem valid url me.

ajax json

No comments:

Post a Comment