javascript - jQuery/Ajax success method implementation -


i have following jquery function on dom ready:

$.ajax({   url : '/weather/',   type: 'get',   //datatype : "json",   success : function(data) {     alert("success");     var jsondata = object.keys(data);     alert(jsondata);     location = "testing";      alert(data.weather);     weather = data.weather;     $("location").text(location);   }   }).settimeout(executequery, 500); 

the ajax call returns proper json using change values of html. however, when line executes,

$("location").text(location); 

the page gets redirected url appends value of 'location' above line. have used these lines elsewhere, without using success function call.

can me should prevent redirect happening?

no, problem lies in variable name using.

don't use location since, if assign string location, redirects given string.

like location="http://nettpals.com"; redirect site.

use other variable name loc

also, if targeting class, prefix . , if targeting id, prefix #

like $('.location') or $('#location').

when use $('location'), trying match location element <location></location>, not want.


Comments

Popular posts from this blog

c++11 - Intel compiler and "cannot have an in-class initializer" when using constexpr -

rest - Spring boot: Request method 'PUT' not supported -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -