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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.