Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Actually You are very close to success... just read these points.</p> <ul> <li>Whenever you are making an ajax request the browser sends a hit on ajax URL with respected parameters and details. On respected URL PHP code executes. It can return data in some format. It can not return data in directly PHP variable.</li> </ul> <p>Formats are:</p> <pre><code>text/html json xml ...... </code></pre> <p>Mainly for cross domain requests we use JSONP. And it means PHP script will return data in JSON. So you will just echo your <code>json_encode</code> in directly script. That will be the response of your ajax request.</p> <ul> <li>Now when you have got the data in ajax function, then jQuery uses success: function(response){ } where you response will come. So variable response will contain JSON. You can access JSON and put data in any tag by using jQuery selector. $().html(response.);</li> </ul> <p>These thing can be analyzed in any browser in debug console. That what is requested and what is returned. even you can use Firebug in Mozilla to inspect ajax request.</p> <p>So you will do three changes.</p> <p>In Ajax function write a success function:</p> <pre><code>var inputdata = $('#inputfield').val('ocean-view'); $('#myform').submit(function(e) { e.preventDefault(); $.ajax({ type: 'GET', url: 'http://serverB.com/detail.php', data: "inputdata="+inputdata, dataType: 'jsonp', success:function(response){ // response will be json type so access it // print ur json in html tag like resposne is {"data":23} $(&lt;jquery selector&gt;).html(reponse.data); } }); </code></pre> <p>});</p> <pre><code>&lt;?php // echo this $inputdata = $_GET['inputdata']; // perform you logic , // make an array to encode it in json echo $_GET['callback'].'('.json_encode($responseArr) .')'; ?&gt; </code></pre> <p>and remove PHP code from h4 tag.</p>
 

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