I have this array, that I want to parse into javascript.
$offerText[] =
(
[0] => Name
[1] => Adres
[2] => ZIP
[3] => CITY
[4] => E-mail
)
I am using this code to do so:
$html .= '<td class="offerteCell"><a href="#" onclick="return addToOffer('.json_encode($offerText).');" class="offerte">Offerte</a></td>';
In my javascript function i want this array to be posted in an ajax call.
function addToOffer(offer_text) {
$.ajax({
url: "offer.php?action=add&offer_text="+offer_text,
cache: false,
method: "GET",
async: false,
complete: function(request) {
if(!request || request.readyState != 4 || request.status != 200) return false;
eval("var obj = "+request.responseText);
$("span.error").hide();
$("p").removeClass('error');
if (obj.errors) {
for (var i in obj.msg) {
$("#error_form_"+i).html(obj.msg[i]).css('display','block');
$("#p_form_"+i).addClass('error');
alert("error");
}
} else {
var offer = $('#OfferContainer');
offer.show().html(obj.html);
var txt = Config.langOfferComplete;
var buttons = {};
buttons[Config.langOk] = false;
buttons[Config.langGoToOffer] = true;
$.prompt(txt,{
submit: function(v,m,f){
if (v) {
window.location = Config.base + '/' + Config.lang + "/offer.htm";
}
},
buttons: buttons
});
}
return false;
}
});
return false;
}
But this is not working does somebody knows what I am doing wrong? I watch the output of my html i get this:
<a class="offerte" naam","adres","postcode","woonplaats","e-mailadres"]);"="" onclick="return addToOffer([" href="#">Offerte</a>
$offerText[]
so you want to dojson_encode( $offerText[0] )
async:false
? That's almost always a bad idea.