Solved

php file not opening

Posted on 2013-01-23
11
298 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
Comment Utility
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
Comment Utility
Are you sure the path of the file is right???

What is showing in firebug?
0
 

Author Comment

by:DS928
Comment Utility
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:DS928
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you, I will try these.
0
 

Accepted Solution

by:
DS928 earned 0 total points
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now