Jump to content

help...JSON.. urgent!


joycecwj

Recommended Posts

 function save(){
 var finalpoint=marker.getPoint();
 eval(finalpoint);
var js=json_encode(finalpoint);


				 $.post('em.php',js, function(json){
					//$("#add-point .error").fadeOut();
					if (json.status == "fail") {
						$("#add-point .error").html(json.message).fadeIn();
					}
					if (json.status == "success") {
						$("#add-point :input[name!=action]").val("");
						var location = json.data;
						alert(location);
					}
				}, "json");
			}

this is my javascript. i want to pass the finalpoint to php....but its didnt work...HELP~~~

 

$geocode=$_POST['finalpoint'];
	echo "here".$geocode;

        $chunks = spliti (",", $geocode);
	$lat= $chunks[0];
	$lng= $chunks[1];
	$query="UPDATE employer SET lat='$lat', lng='$lng' WHERE id='1' ;";
$res = mysql_query($query);

	if ($res) {
		success(array('lat' => $lat, 'lng' => $lng));
	} else {
		fail('Failed to add point.');
	}
	exit;
}

function map_query($query) {
	// Connect
	mysql_connect('localhost', 'root', '')
	    OR die(fail('Could not connect to database.'));

	mysql_select_db('map');
	return mysql_query($query);
}

function fail($message) {
	die(json_encode(array('status' => 'fail', 'message' => $message)));
}

function success($data) {
	die(json_encode(array('status' => 'success', 'data' => $data)));
}

here is the php. :'(

Link to comment
Share on other sites

i ran your code through a Json parser  thats the error it returned.

how bout if i replace the  line from  $.post('em.php',js, function(json){        to  $.post($("#add-point").attr('action'),data, function(json){  ??

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.