My jquery rendered partial isnt running the javascript inside
So Im sending some parameters to my controller (via ajax) in order to retrieve some records, and then displaying the results with javascript by loading a partial. In the partial Im looping through the array of retrieved records and displaying each, but Im also trying to call a javascript function in my page's head tag, and passing data from my array.
But the javascript call isnt working, infact, when I use firebug to look at the page the javascript isnt even there.
Basically Im trying to update a google map with the retrieved information.
Here is my rendered partial:
<ol class="shop_list">
<% @开发者_如何学JAVAshops.each do |s| %>
<script type="text/javascript">
shopMarker(<%= s.latLng %>); //This would be a comma separated string containing latitude and longitude
</script>
<li><%= link_to s.shop_name ,"#" %></li>
<% end %>
</ol>
Here is the jquery calling the partial when the controller responds to the JS:
$("#shop_results").html("<%= escape_javascript(render("shop_results")) %>");
and here is the function Im calling in the header:
function shopMarker(latLng){
var marker = new google.maps.Marker({
map: map,
position:latLng
});
map.setCenter(latLng);
}
What am I missing?
Could you post your controller response and the link / form you're using to render shop results in the first place?
Your controller should look something like:
respond_to do |format|
format.js
end
Your response should be called action_name_here.js.erb
.
Finally, by default on an XHR request your initial call to the controller should be using the JS response, but can you confirm by looking in your logs that it's saying ... responding with JS
" format?
精彩评论