找到你要的答案

Q:ajax post to php dynamically

Q:Ajax后PHP动态

I have a signup form which uses

function user_reg(user_name,user_email,user_pswd)
{
	var serverpath=window.location; 
	alert(serverpath);
		var dataString = 'name='+ user_name + '&email=' + user_email + '&pswd=' + user_pswd + '&page=user_reg';
		$.ajax({
			type: "POST",
			url:  "/pages/login.php",
			data: dataString,
			cache: false,
			success: function(response)
			{
				var response_brought = response.indexOf('registered_successfully=yes');
				if (response_brought != -1) 
				{
					$('#signup_thanks').openModal();
				//	window.location.replace(response);
				}	
			}
		});
}

this function is in signup.js file which is is in ./js folder. This script file is needed in both index.php which is in the root and in signup.php file which is in ./pages folder. And the above code posts the data to login.php which is a;sp in ./pages folder. when I include signup.js in index.php the above code works but when I add it in signup.php it won't post to ./pages/login.php it post to ./pages/pages/login.php which don't exist. So how can I do this. Please help. Thankyou

我有一个注册表格的使用

function user_reg(user_name,user_email,user_pswd)
{
	var serverpath=window.location; 
	alert(serverpath);
		var dataString = 'name='+ user_name + '&email=' + user_email + '&pswd=' + user_pswd + '&page=user_reg';
		$.ajax({
			type: "POST",
			url:  "/pages/login.php",
			data: dataString,
			cache: false,
			success: function(response)
			{
				var response_brought = response.indexOf('registered_successfully=yes');
				if (response_brought != -1) 
				{
					$('#signup_thanks').openModal();
				//	window.location.replace(response);
				}	
			}
		});
}

this function is in signup.js file which is is in ./js folder. This script file is needed in both index.php which is in the root and in signup.php file which is in ./pages folder. And the above code posts the data to login.php which is a;sp in ./pages folder. when I include signup.js in index.php the above code works but when I add it in signup.php it won't post to ./pages/login.php it post to ./pages/pages/login.php which don't exist. So how can I do this. Please help. Thankyou

answer1: 回答1:

Try this and see url: "../pages/login.php",

Try this and see url: "../pages/login.php",

javascript  php  ajax