2013-10-22 35 views
0

我试图使用jQuery ajax.but在这个URL,我们使用特殊字符从一个网页的URL发送到另一个页面如下图所示使用jQuery AJAX

var video='https://youtube.com/v/e6howcqnxfw&start=25&end=80'; 

      $.ajax(
      { 
       type: 'POST', 
       url: 'video.php',  
       data: 'video='+video, 
       success: function(response) 
       { 
        $('#popup_box').show(); 
        $('#video').html(response);  
       }, 
       error:function() 
       { 
        alert('Error'); 
       } 
      }); 

但向YouTube发送一个网址到另一个页面在下一页我得到的价值为"https://youtube.com/v/e6howcqnxfw" 我越来越var video值从数据库。 在这个我没有得到完整的网址然后如何获得完整的网址与特殊的文字记录(&)。

谢谢!

+0

https://youtube.com/v/e6howcqnxfw?start=25&end=80 –

回答

1

你尝试过吗?

encodeURIComponent() 

decodeURIComponent() 
+0

非常感谢你 – lalith222

+0

NP,欢迎您 – reyaner

0

你缺少?使用?代替&

var video='https://youtube.com/v/e6howcqnxfw?start=25&end=80'; 
+0

我得到URL值形式的数据库,而不是静态 – lalith222

0

一种解决方法是打破你的网址成几个部分:

var video='https://youtube.com/v/e6howcqnxfw; 
var start_time = 25; 
var end_time = 80; 

那么,你的AJAX后看起来就像是:

$.ajax(
      { 
       type: 'GET', 
       url: 'video.php?video='+video+'&start='+start_time+'&end='+end_time, 
       success: function(response) 
       { 
        $('#popup_box').show(); 
        $('#video').html(response);  
       }, 
       error:function() 
       { 
        alert('Error'); 
       } 
      }); 

其他所以lution是通过函数encodeURIComponent(video);来逃避你的整个URL,然后你可以用urldecode() PHP函数解码URL(在服务器端),并获得所有的变量。