Solved

Im getting 500 Internal Server Error when using .post() jquery

Posted on 2011-09-28
22
364 Views
Last Modified: 2012-05-12
Im trying to use .post()  in a jquery sumbit form
the ur l= handelSpamDb.php

and I get 500 Internal Server Error
            26ms

$("#"+popup_form_id).submit(function(e) {
                         //   alert("Hello world!");
							//fElement.attr('flag','1');
							e.preventDefault();
						//"mark" the input name =flag as spam 
						    $(":hidden[name='flag']","#"+popup_form_id).val("on");
							fElement.toggle();
							//$.ajax(
							alert($(this).serialize() +"tryinggg");
							$.post(url,$(this).serialize());
								
							
					})

Open in new window

0
Comment
Question by:Nura111
  • 13
  • 6
  • 3
22 Comments
 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 36719938
That has to be an error in 'handelSpamDb.php' because jquery does not run on the server.  Do you have an alternate way of testing 'handelSpamDb.php' like a simple HTML form that will POST to it?
0
 

Author Comment

by:Nura111
ID: 36720002
the code in theat file was previuosly in a diffrent location wraped by if isset[formSumbit]
and it was working

Do I still need ro access the variables in $_POST see code
$id = $_POST['id'];

$email = $_POST['email'];



$sql= BaseModel::getSqlObject();

$query = "SELECT * FROM BlackList WHERE email_address = '$email'";	

	     

	if (($result=$sql->Query($query)) === FALSE)

      die(ShowError("Server Query Error"));

$num = $result->num_rows;

	   

	//check if email is not already exist in BlackList

	if ($result->num_rows == 0){

   			 $insert_query = "INSERT INTO BlackList(email_address) VALUES ('$email')";

			 

	 if (($result=$sql->Query($insert_query)) === FALSE)

           	die(ShowError("Server Insert Query Error"));

		}

		

		$insert_query =	"UPDATE ServiceRequests SET spam = 1 WHERE id = '$id'";

		if (($result=$sql->Query($insert_query)) === FALSE)

           	die(ShowError("Server Insert Query Error service"));





			die ("ok");

         

	

		

 

		

		}

Open in new window

0
 

Author Comment

by:Nura111
ID: 36720039
Does it matter who is the referral page?
0
 

Author Comment

by:Nura111
ID: 36720076
the fire bug debug is saying the mistake is in       
jquery.js (line 7950)
0
 

Author Comment

by:Nura111
ID: 36720110
Is it ok to gop in the script to $_POST is it suppose to be there after sent it with .post()?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36720144
The Firebug error is a different subject because Firebug can't tell you about server errors, only javascript and DOM.
0
 

Author Comment

by:Nura111
ID: 36720151
Is it ok to go in the refred script to $_POST is it suppose to be there after sent it with .post()?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
ID: 36720166
I'm not sure I understand.  If you send the data as a POST like you are showing, then it has to be received in the $_POST array.
0
 

Author Comment

by:Nura111
ID: 36720212
Ok so is nyone can help in the server error issue?
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36720309
What is the value of url from the post call? Are you sure it's the file that is handling your post values?
0
 

Author Comment

by:Nura111
ID: 36720318
Do you mean what I wrote in the question    url = handelSpamDb.php

and yes Im sure I attched the code also
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:Nura111
ID: 36720327
what is the common way im suppose to handle the errors in the jquery submit?
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36720407
What I was asking was if we were sure that the value in url is actually the file we expect the request to be made against. The code shown does not show how the 'url' variable is assigned - so I asked.

.post supports using an .error() function to handle when the post is not returned successfully. It would look something like:

$.post(url,$(this).serialize()).error(function() { alert('post failed'); });

Open in new window


Are there any errors that show up in the webserver logs? If this is apache on linux, it may be in /var/log/https/error_log or something but that would depend on the system configuration.
0
 

Author Comment

by:Nura111
ID: 36720437
Its on vmware there is only one filr in log folder and it doesnt show anything
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36720454
Can you type the page address in the address bar and get it to load without error?
0
 

Author Comment

by:Nura111
ID: 36906041
no its not working is well its cant find it but the php file is there in the public folder like all the other ones that I can get access directly by entering the url
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36906055
Can you check the permissions of the file? Are they the same as the other files that are working?
0
 

Author Comment

by:Nura111
ID: 36906068
yes same pemisiions read and write
0
 
LVL 11

Expert Comment

by:MacAnthony
ID: 36906134
Same file extension? Like the ones working aren't .php and this one .inc or something, right?

There has to be something different, I'm just taking guesses at what they could possibly be.
0
 

Author Comment

by:Nura111
ID: 36906143
no there are both .php extention
0
 
LVL 11

Assisted Solution

by:MacAnthony
MacAnthony earned 250 total points
ID: 36910123
And there is nothing in either the apache or php error logs?

I'm kind of at a loss for ideas of what could cause this.
0
 

Author Comment

by:Nura111
ID: 36911311
what are the possible location the log file can be?
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
This video teaches users how to migrate an existing Wordpress website to a new domain.

747 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

13 Experts available now in Live!

Get 1:1 Help Now