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

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -