Jump to content

JSON working when .js file, but not when created by .php


johnwcj

Recommended Posts

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.