jQuery用字符串变量替换引号中的url。

时间:2022-03-28 16:48:43

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... 

2 个解决方案

#1


1  

You mean like:

你的意思是:

$(document).ready(function(){

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

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

#2


4  

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... 

#1


1  

You mean like:

你的意思是:

$(document).ready(function(){

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

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

#2


4  

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...