कार्य: जब मैं चुनिंदा टैग ग्राहक से चुनता हूं (मेरे पास ग्राहक_आईडी है), तो उसे डीबी में अनुरोध करना होगा और सभी ग्राहक फ़ील्ड वापस कर देना होगा। और फिर यह स्वचालित रूप से कुछ इनपुट भरना होगा। मैं AJAX + jQuery बनाने की कोशिश करता हूँ। अजाक्स अच्छा है। अब यह काम कर रहा है!अजाक्स प्रतिक्रिया गलत तरीके से चल रही है
यहाँ जेएस है:
मैं इस आंकड़ा बाहर:
<script>
$(document).ready(function() {
$('#customer_load').change(function() {
$.ajax({
url: '<?= $this->url(array('action' => 'ajax', 'controller' => 'baza')) ?>',
type: 'POST',
dataType: 'json',
data: {
// list of request parameters
'customer_id': $(this).attr('value')
},
success: function(data) {
//alert(data.current_discount);
$('#extra_discount').val(data.extra_discount);
$('#current_discount').val(data.current_discount);
$('#customer_number').val(data.customer_id);
}
});
});
});
पीएचपी init:
$this->_helper->AjaxContext()->addActionContext('add', 'json')->initContext('json');
अजाक्स कार्रवाई:
$id= $this->_getParam('customer_id');
$result = $this->_customers->fetchSelected($id);
$this->view->customers = $result;
$this->_helper->json($result);
एचटीएमएल:
<select name="customer_id" id="customer_load" style="width:300px;">
<option value="0">Выберите заказчика</option>
?php foreach ($this->customers as $cus): ?>
<option value="<?= $cus['customer_id'] ?>"" <?php if ($cus['customer_id'] == $this->form_data['customer_id']) echo "selected"; ?> ><?= $cus['lastname'] . " " . $cus['name'] ?></option>
<?php endforeach; ?>
<option value="new" onclick="NewCustomer()">Новый заказчик</option>
</select>
क्या आप अपने अजाक्स कॉल '/ एड' में दिए गए यूआरएल को हल करने के लिए किसी प्रकार के मॉड-रीराइट का उपयोग कर रहे हैं? – dbf
अस्थायी रूप से अक्षम है 'isXmlHttpRequest' नियंत्रक में जांचें और पहले ब्राउज़र में सीधे AJAX कार्रवाई का परीक्षण करें। एक बार जब आप इसे काम कर लेते हैं तो सुरक्षा की स्थिति जोड़ें और आपको AJAX कॉल लागू करें। सलाह एलेक्स के लिए – Alex
धन्यवाद, मैं '/ Baza/जोड़ने' के लिए यूआरएल को बदलने, लेकिन मेरे फ़ायरबग में यह पोस्ट http://www.voskmodel.dev/baza/add \t 200 ठीक 65ms मैं कहीं नहीं – Stopper