0

i want to add a javascript code , which i getting from the server to my view .

is this possible .

i am doing this

 jQuery(".city").change(function(){
 var address = jQuery('#business-address').val();
 var city = jQuery('.city').val();
 var state = jQuery('.state').val();
 var country = jQuery('.country').val();
 var address_string = address+","+city+","+state+","+country;
 jQuery.ajax({
 type: "post",
 url: baseurl+"home/auth/create_google_map_from_address",
 data:{address:address_string},
 success: function(data,status){
 var data_array = JSON.parse(data); 
 var latitude = data_array['map']['markers']['marker_0'].latitude;
 var longitude = data_array['map']['markers']['marker_0'].longitude;
 var map_js = data_array['map'].js;
 var map_html = data_array['map'].html;
 alert(latitude);
 jQuery('#gmap_js').html(map_js);
 } 
 });
 });

i am getting a javasript code to variable map_js

i want to add this code to the html page ,

currently i am using jQuery('#gmap_js').html(map_js);

but it is not working , how to do this .

this is map_js

enter image description here

please help...........

asked May 9, 2012 at 10:38

1 Answer 1

1

You can do it this way, make you use escape character back slash \ where you need as you will see in the example code.

var map_js = '<script language="javascript" type="text\/javascript"> alert("Js");<\/script>'
jQuery('head').append(map_js);

Jeromy French
12.2k19 gold badges79 silver badges136 bronze badges
answered May 9, 2012 at 10:57
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.