Solved

php file not opening

Posted on 2013-01-23
11
306 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to send commands to switch via telnet programatically 15 86
Conformation code 4 35
Ajax success not firing alert 6 42
Position image fpdf 4 18
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

734 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