开发者

jQuery replace url in quotes with a string variable

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜