Solved

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

Posted on 2011-09-28
22
368 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 83

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 83

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 83

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
 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

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…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

785 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