开发者

jQuery replace url in quotes with a string variable

开发者 https://www.devze.com 2023-02-15 11:29 出处:网络
Can I use a string and substitute it for the quotes where the arrow is pointing below? $(document).ready(function(){

Can I use a string and substitute it for the quotes where the arrow is pointing below?

$(document).ready(function(){      
   $.ajax({         
   type: "GET",  
   url: "http://mydomain/test.xml",      <---- Right here can I use a variable like str
   dataType: "xml",          
   success: 
   function(xml){  
     etc..开发者_运维知识库. 


Yes, you can:

$(document).ready(function(){

var ajaxUrl = "http://mydomain/test.xml";

   $.ajax({         
   type: "GET",  
   url: ajaxUrl,      <---- Right here can I use a variable like str
   dataType: "xml",          
   success: 
   function(xml){  
     etc... 


You mean like:

$(document).ready(function(){

   var someUrl = "http://mydomain/test.xml";

   $.ajax({         
   type: "GET",  
   url: someUrl,
   dataType: "xml",          
   success: 
   function(xml){  
     etc... 
0

精彩评论

暂无评论...
验证码 换一张
取 消