48085

do I need getJson at all?

Question:

$(document).ready(function () { $(".viewmap").click(function () { var id = $(this).attr("id"); var responseURL = "~/changemap?id=" + id; //alert(responseURL); $.ajax( { url: responseURL, dataType: "json", type:"GET", success: function (dt) { initialize(dt.Latt, dt.Longt); } } ); } ); });

I use that script to make an ajax call to the page changemap.cshtml which does the following

@{ if(!IsPost) { if(!Request.QueryString["id"].IsEmpty()&&Request.QueryString["id"].IsInt()) { var countryId=Request.QueryString["id"]; var db=Database.Open("GoogleMapView"); var dbCmd="SELECT * FROM places WHERE id=@0"; var row=db.QuerySingle(dbCmd,countryId); if(null!=row) { Json.Write(row,Response.Output); } } } }

That is to return the queried data from the database in json format to the client. The Initialize function is defined as

function initialize(lat,lng) { var mapOptions = { center: new google.maps.LatLng(lat,lng),zoom: 8,mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("gmap"),mapOptions); }

But when I click the div tag of class viewmap, nothing happens. I think I miss some more script to get my application to work correctly.

I only try to implement a simple google map view in which once the user clicks a place name as a hyperlink will reload the map that matches with it.

Answer1:

I think

var responseURL = "~/changemap?id=" + id;

should be

var responseURL = '@(Url.Content("~/changemap")+"?id=")' + id;

Answer2:

try thr following

success(data){ initialize(data.d.Latt, data.d.Longt); }

for more reference as in why d is used check the following link

http://encosia.com/never-worry-about-asp-net-ajaxs-d-again/

Recommend

  • asp.net razor web pages validation and using multiple forms
  • do I need getJson at all?
  • display json value in select tag(view) zend framework 2
  • Receiving SOAP notifications from eBay api into ASP variable?
  • QWidget reports wrong width value
  • Why is this Exception?- The relationship between the two objects cannot be defined because they are
  • DropDownList not behaving as expected
  • set palette color to blue in gnuplot
  • MINIX: sys_call: ipc mask denied SENDREC from 1 to 1
  • There was an error parsing the query. [ Token line number = 1,Token line offset = 52,Token in error
  • Working with EditorTemplates and radio buttons
  • Dereferenceing on casting the void pointer to float*/int*
  • Process.StartTime Access Denied
  • Getting JavaScript runtime error: irrationalPath, what does it mean?
  • Passing Props from State to Child
  • proxy request in node.js / express
  • How can I extract results of aggregate queries in slick?
  • Needing to do .toArray() to get output of mongodb .find() on key name not value
  • MongoDB in PHP using aggregate to group by _id is null not working
  • How to extract text from Word files using C#?
  • How to check if every primary key value is being referenced as foreign key in another table
  • Sending data from AppleScript to FileMaker records
  • Can I make an Android app that runs a web view in Chrome 39?
  • Symfony2: How to get request parameter
  • log4net write single file for each call to log.info
  • Getting error when using KSoap library to consume .NET web services
  • Turn off referential integrity in Derby? is it possible?
  • LevelDB C iterator
  • Linking SubReports Without LinkChild/LinkMaster
  • How to get NHibernate ISession to cache entity not retrieved by primary key