使用ajax js,将数组传递给php

时间:2015-08-05 10:35:11

标签: javascript php arrays ajax

我创建了一个字符串数组:a = "details.html?id=8220&inr=4241&marke=Ford&modell=Focus&art=Gebrauchtwagen&standort=" a.scan(/\d+/).join # => "82204241" ,其中有两个值id +已选中,我试图通过php传递此数组来更新数据库..我是新手ajax所以我不知道如何正确地做到这一点..当它工作很酷的时候我就是从表单中插入数据。但是我在这个问题上做得很糟糕。我点击提交btn后从表中收集值,请帮助!

JS代码:

'id=$id&value=$value'

PHP代码:

function ejecutarAjax(datos) {
    ajax = objetoAJAX();
    ajax.onreadystatechange = enviarDatos;
    ajax.open("POST", "trst.php");
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.send(datos);
}


var datos = new Array,
     queryString = '',
     id = new Array(),
     status = new Array(),
checkStatus = document.getElementsByName('check');

for (i = 0; i < checkStatus.length; i++) {
    id[i] = checkStatus[i].getAttribute('data-id');
    status[i] = checkStatus[i].checked;
    datos += "idStatus=" + id[i] + "&checkStatus=" + status[i] + "&";
}
queryString = datos + "transaccion=upset";
//console.log(queryString);
ejecutarAjax(queryString);

0 个答案:

没有答案