select下拉框的值传入jquery,并用ajax传到另一个php页面,老是传不过去。
请大大门帮我看一下,到底为什么传不了值。
本页面:
<script> <br /> $(function(){ //获取多选下拉菜单里面的值 <br /> $("#submit").click(function(){ <br /> var ar=","; // 机智如我,用字符串而不是数组的形式连接起来,就不涉及ajax传送数组的问题了 <br /> $("option:selected").each(function(){ <br /> ar+=$(this).text()+","; <br /> }); <br /> alert("新生成的字符串为:"+ar); <br /> $.post("sms.php", {cla:ar},function(data,status){alert(data)} <br /> ); <br /> }); <br /> }); <br /></script>
接收传值的页面:
$cla=$_POST["cla"];
echo $cla;
include_once("conn.php");
$sql="update class_string set class_string='$cla' where teacher='ma'";
$result = mysql_query($sql);
// $homework=$_POST['homework'];
// $deadline=$_POST['deadline'];
// echo $homework;
// echo $deadline;
?>
回复讨论(解决方案)
<?phpif($_POST) { print_r($_POST); exit;}?><script src=scripts/jquery-1.8.3.min.js></script><script type="text/javascript">$(function(){ //获取多选下拉菜单里面的值 $("#submit").click(function(){ var ar=","; // 机智如我,用字符串而不是数组的形式连接起来,就不涉及ajax传送数组的问题了 $("option:selected").each(function(){ ar+=$(this).text()+","; }); alert("新生成的字符串为:"+ar); $.post(location.href, {cla:ar}, function(data,status){alert(data)}); }); });</script> <select><option>a</option><option>b</option><option>c</option><option>d</option></select><input type=button id=submit value=ok>
虽然还没找到原因,但是还是谢谢版主
sms.php改成http开头的绝对路径试试?
找到原因了。我用这个button触发ajax的同时,又用它来提交form表单了,而这是不被允许的。所以出现了一些奇奇怪怪的报错。谢谢各位,结贴。
你没贴全代码,人家就不好分析了
嗯,是没贴全。但是我压根儿没想到问题会出在一个input按钮上。还是很谢谢大家。
楼主 怎么实现将下拉列表的值传给另外一个php页面的啊?求教

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Laravel simplifies HTTP verb handling in incoming requests, streamlining diverse operation management within your applications. The method() and isMethod() methods efficiently identify and validate request types. This feature is crucial for building

The Storage::download method of the Laravel framework provides a concise API for safely handling file downloads while managing abstractions of file storage. Here is an example of using Storage::download() in the example controller:
