2012-05-17 206 views
0

我目前正在使用聯繫我們表單發送用戶信息給uservoice。我正在使用一個jQuery代碼發送一個json請求給用戶發音。發送JSON請求到uservoice

下面的代碼:

$('#test_form').submit(function(evt) { 

    evt.preventDefault(); 



    var uvSubdomain = "initech";/ 



    var uvKey = "5JVoVrAGdl4pMkcEkIeIDA"; 




    var message = $('#message').val(); 

    var subject = $('#subject').val(); 

    var name = $('#name').val(); 

    var email = $('#email').val(); 



    $.jsonp({ 

     url: 'https://' + uvSubdomain + '.uservoice.com/api/v1/tickets/create_via_jsonp.json\\?callback=?', 

     data: { 

      client: uvKey, 
      ticket: { 
       message: message, 
       subject: subject 
      }, 
      name: name, 
      email: email 
     }, 

     success: function(data) { 

      alert('Successfully submitted ticket!'); // You might want to redirect the user here, or show a stylized message to them. 

     }, 

     error: function(d, msg) { 

      alert("Error"); 

     } 

    }); 

    return false; 
}); 

現在我想送與PHP的幫助下,JSON請求。

如果您有任何建議或代碼,請讓我知道。

感謝您

+0

_Now我想發送帶有JSON請求PHP的幫助__你的意思是你想要作爲json的響應? – itachi

回答

0

你可以使用curl擴展:

$c = curl_init(); 
curl_setopt($c, CURLOPT_URL, 'https://test.com'); 
curl_setopt($c, CURLOPT_POST, 1); 
curl_setopt($c, CURLOPT_POSTFIELDS, 'name1=value1&name2=value2'); //post data 
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); 
$response = curl_exec($c); 
curl_close($c); 

,如果你連接到https的網站,你必須添加的這一個:

//easy solution 
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false); 

//secure solution 
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true); 
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($c, CURLOPT_CAINFO,"/path_to_certificate/cert.crt"); 
+0

替代此方法?沒有捲曲延伸我們怎麼能使用它? – Seeker