Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is another possibility if you need to post calls to a page on another domain. Let's say your Javascript is being run from index.php. You might create a file called ctexter.php. ctexter.php would use curl to make the post request to <a href="http://cabbagetexter.com/send.php" rel="nofollow">http://cabbagetexter.com/send.php</a>, and would then output the response (the output from) send.php. So, if index.php makes an ajax call to ctexter.php, and ctexter.php is outputting the response from send.php, you have in effect achieved your goal.</p> <p>You could make the curl post requests with this function:</p> <pre><code>function post_request($url, $data) { $output = array(); foreach ($data as $key =&gt; $value) { if(is_object($value) || is_array($value)){ $data[$key] = serialize($value); } } $output = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); $result = curl_exec($ch); if ($result) { $output['status'] = "ok"; $output['content'] = $result; } else { $output['status'] = "failure"; $output['error'] = curl_error($ch); } curl_close($ch); return $output; } </code></pre> <p>where $url is (obviously) the url to post to, and $data is an associative array containing the data you want to submit.</p> <p>Then on ctexter.php you could do something like:</p> <pre><code>// Since we already built the post array in the // ajax call, we'll just pass it right through $response = post_request("http://cabbagetexter.com/send.php", $_POST); if($response['status'] == "ok"){ echo $response['content']; } else{ echo "It didn't work"; } </code></pre> <p>Finally, hit ctexter.php using <a href="http://api.jquery.com/jQuery.post/" rel="nofollow">JQuery .post()</a>:</p> <pre><code>$.post("ctexter.php", { firstparamname: "firstparamvalue", somethingelse: "llama" }, function(data) { alert("It worked! Data Loaded: " + data); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload