johnwcj Posted February 22, 2010 Share Posted February 22, 2010 Hi I have a really simple bit of PHP that creates a really basic JSON string like this: {"salescost":"100.00","prepcost":"200.00","contentcost":"300.00","designcost":"400.00","executioncost":"500.00","revenue":"2,000.00"} I then call this information through an AJAX request using JQuery in an HTML file. If I save the outout of the PHP file as a .js everything works fine, but using the PHP returns nothing. My JQuery code is: $.ajax({ url: "get_quote.php", dataType: "json", data: "jobID=" + $("#txt_jobid").val(), success: function(json){ $("#txt_salesCost").val(json.salescost); $("#txt_prepCost").val(json.prepcost); $("#txt_contentCost").val(json.contentcost); $("#txt_designCost").val(json.designcost); $("#txt_executionCost").val(json.executioncost); $("#txt_revenue").val(json.revenue); }, failure: function(){ $("#txt_salesCost").val(0); $("#txt_prepCost").val(0); $("#txt_contentCost").val(0); $("#txt_designCost").val(0); $("#txt_executionCost").val(0); $("#txt_revenue").val(0); } }); And the key bits of the PHP file are: <?php header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" ); header("Cache-Control: no-cache, must-revalidate" ); header("Pragma: no-cache" ); header("Content-type: application/json"); ... code to build content ... echo json_encode($a); ?> Any ideas what the problem might be? I've tried a variety of things as the content type, including "text/html", but to no avail. Any help would be very much appreciated. John Link to comment https://forums.phpfreaks.com/topic/192869-json-working-when-js-file-but-not-when-created-by-php/ Share on other sites More sharing options...
johnwcj Posted February 22, 2010 Author Share Posted February 22, 2010 Found the solution. Replaced this: url: "get_quote.php", dataType: "json", data: "jobID=" + $("#txt_jobid").val(), with this: url: "get_quote.php?jobID=" + $("#txt_jobid").val(), dataType: "json", data: "", Link to comment https://forums.phpfreaks.com/topic/192869-json-working-when-js-file-but-not-when-created-by-php/#findComment-1015886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.