Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php file not opening

Posted on 2013-01-23
11
Medium Priority
?
310 Views
Last Modified: 2013-01-30
I'm trying to open a php while passing along these three values.  I know I'm at the point because my alert is coming up, but file is not opening.  Any help is appreciated.  Thank you.

case "Place":
	alert("Hello Place");
	var Rid = $('#Doggie').val(), Cid = $('#Kitty').val(),	Aid = $('#Pig').val();
	$.post('ajax/result_place.php', { Rid: "Rid", Cid: "Cid", Aid: "Aid"} );
	break;

Open in new window

0
Comment
Question by:DS928
11 Comments
 

Author Comment

by:DS928
ID: 38812960
Tried this, but still not opening...

$(document).ready(function()
{
var Rid = $('#Doggie').val(), Cid = $('#Kitty').val(),	Aid = $('#Pig').val();
$.ajax({
type: "POST",
url: "result_place.php",
data: {"Rid":Rid,"Cid":Cid,"Aid":Aid}, 
cache: false,
success: function (html) {
}
});
})

Open in new window

0
 
LVL 12

Expert Comment

by:sivagnanam chandrakanth
ID: 38813143
Are you sure the path of the file is right???

What is showing in firebug?
0
 

Author Comment

by:DS928
ID: 38813216
Path is right.  I have fuve different php files that I can possibly load.  Maybe there is a way from javascript that I can change the form action to select the proper file?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 38813457
OK, try this and see what the error is

$(document).ready(function()
{
var Rid = $('#Doggie').val(), Cid = $('#Kitty').val(),	Aid = $('#Pig').val();
$.ajax({
type: "POST",
url: "result_place.php",
data: {"Rid":Rid,"Cid":Cid,"Aid":Aid}, 
cache: false,
success: function (html) {
},
error: function (xhr, ajaxOptions, thrownError){
alert(thrownError);
}
});
})

Open in new window

0
 

Author Comment

by:DS928
ID: 38813579
Path is right.  I have fuve different php files that I can possibly load.  Maybe there is a way from javascript that I can change the form action to select the proper file?
0
 

Author Comment

by:DS928
ID: 38813754
OK, no error, no nothing?  Here is where the code is being called from.  The alert comes up so I assume that whatever is behind the alert is also coming up?

<form onsubmit="return doSomething();">
<select name="Doggie" size="20" style="width:250px" class="Doggie" id="Doggie" >
</select>
<select name="Kitty"  size="20" style="width:250px" class="Kitty" id="Kitty" >
</select>
<select name="Pig"  size="20" style="width:250px" class="Pig" id="Pig">
</select>
        
<input type="submit" value="Show" name="select" />
 <label for="Kitty"></label>
 <div align="center"></div>
 <label for="Pig"></label>
 <div align="center"></div>
 <div align="center">
 <p>
<input type="hidden" input name="Glass" id="Glass"/>
</p>
</form>

Open in new window


and the function being called.
function doSomething() {
    var g = $("#Glass").val();
	switch(g)
	{
	case "Place":
	$(document).ready(function()
	{
	var Rid = $('#Doggie').val(), Cid = $('#Kitty').val(),	Aid = $('#Pig').val();
	$.ajax({
	type: "POST",
	url: "result_place.php",
		data: {"Rid":Rid,"Cid":Cid,"Aid":Aid}, 
		cache: false,
		success: function (html) {
		},
		error: function (xhr, ajaxOptions, thrownError){
		alert(thrownError);
		}
		});
		})
		break;
	case "Cuisine":
	$(document).ready(function()
	{
	var Cid = $('#Doggie').val(), Aid = $('#Kitty').val(),	Fid = $('#Pig').val();
	$.ajax({
	type: "POST",
		url: "result_cuisine.php",
		data: {"Cid":Cid,"Aid":Aid,"Fid":Fid}, 
		cache: false,
		success: function (html) {
		},
		error: function (xhr, ajaxOptions, thrownError){
		alert(thrownError);
		}
		});
		})
		break;
	case "City":
		alert("Glass = " + g);
		break;
	case "State":
		alert("Glass = " + g);
		break;
	case "ZipCode":
		alert("Glass = " + g);
	break;
	}
	
	
	return false;
}

Open in new window

0
 
LVL 9

Expert Comment

by:crazedsanity
ID: 38814462
It seems to me that the most likely error here is that you're using a relative URL instead of an absolute one, so it only seems like it's going to the right place.  If the actual URL is "/ajax/result_cuisine.php", and it's called from "/menu/something.php", the actual URL that it will try to use would be "/menu/ajax/result_cuisine.php".

I would suggest trying this in Chrome (Chromium on Linux) or Firefox.  In Chrome, there's a "javascript console" under the tools submenu, which has a "network" tab: bring that up, and watch the javascript run... if there's an error, it will appear in the console or (most likely) you'll get a 404 error or similar in the network tab.  In Firefox, just install Firebug, activate it, and do the same thing.
0
 
LVL 9

Expert Comment

by:crazedsanity
ID: 38814472
What I sometimes do to actively debug javascript (without having to set breakpoints in it) is to write the *.js file so it has callable functions.  Once it's written, I load the page & use the browser's Javascript console to execute the command and view the results.  With some simple logging to the console using console.log("stuff") (don't use this in IE, it will cause the JS to break), I've been able to find and fix the problems pretty quickly.
0
 

Author Comment

by:DS928
ID: 38815935
Thank you, I will try these.
0
 

Accepted Solution

by:
DS928 earned 0 total points
ID: 38819778
OK, gave up on this.  I switched it to this, changing the form action dynamicaly and that is working fine.
Code in the form....
<form name="Animals" method="post" onsubmit="return OnSubmitForm();">

Open in new window

The function...
function OnSubmitForm() {
    var g = $("#Glass").val();
	switch(g)
	{
		case "Place":
			document.Animals.action ="result_place.php";
                                   break;
		case "Cuisine":
			document.Animals.action ="result_cuisine.php";
		break;
		case "City":
			document.Animals.action ="result_city.php";
		break;
		case "State":
			document.Animals.action ="result_state.php";
		break;
		case "ZipCode":
			document.Animals.action ="result_zip.php";
		break;
	}
}

Open in new window

0
 

Author Closing Comment

by:DS928
ID: 38834540
The other way doesn't seem to work, so I tried changing the action on the form to call the proper php according to the value of a hidden textbox on the form.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question