I want to get the data loaded into my PHP file in javascript. This is what I do:
$("#submit").click(function() { // GET VALUE OF APPID var appid = $("#appid").val() // GET JSON FROM PHP $.ajax({ type: 'GET', url: '../loadjson.php', data: { 'appid': appid }, success: function (data) { alert('success'); }, error: function(jqXHR,error, errorThrown) { if(jqXHR.status&&jqXHR.status==400){ alert(jqXHR.responseText); }else{ alert("Something went wrong"); } } }); });
When I click the button, I get the value of the text field and call the ajax function. my javascript file is in root / js / file.js file and my php file is in root / loadjson.php file
My PHP file:
<?php if(isset($_POST['appid']) && !empty($_POST['appid'])) { $appid = $_POST['appid']; } $json_url ='http://api.url.com/api/gateway/call/1.4/getApp?appid=' . $appid; $ch = curl_init($json_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $str = curl_exec($ch); curl_close($ch); $data = json_decode($str); $array = $data; $object = $array->app[0]; echo $object;
? >
The problem is that I always get a warning with “Something went wrong,” but I cannot find a solution. Does anyone see my mistake?
I get this: 
jsfiddle: http://jsfiddle.net/wKe2U/
source share