2013-10-22 31 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(在服務器端),並獲得所有的變量。