PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Dec 13, 2018 2:24 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
PostPosted: Tue Apr 17, 2012 8:36 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
The following programs came from OSC 2.3.1.
I modified categories.php so that it can automatically
acquire products information from other websites. However, I do not know how to insert the information back.

Here is my program:
http://pastebin.com/a5GjTqWy
on line 928 onchange() first check the validity of the
products number by calling chk_ISBN.
After successfully checked, it called send_findbooks
on line 908, which evoke ajax.request to acquire
information from send_one_isbn.php, which is shown
http://pastebin.com/sBMXtd5v
The information is obtained and parsed.
But I do not know how to pass the results back.
I cannot display the results in FilltheForm in line 918. Why?
Perhaps, should I insert the results directly into the
database, instead of passing back?

Any suggestion?


Last edited by wvoyance on Thu Apr 19, 2012 10:50 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Wed Apr 18, 2012 10:52 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
Usually with ajax I don't think of passing stuff back because that brings to mind return values. But it looks like you are trying to get your FilltheForm callback function working, yes? How do you know the information is obtained and parsed by send_one_isbn.php, did you add a print statement somewhere or examine the http response in firebug? If you see the Title, Author, etc. info coming back from the ajax call (as seen in firebug), then you should be able to add an alert statement in your FilltheForm function to see it.

However, inserting the results directly into the database inside your ajax function is actually a safer method because it means there is one less network call that needs to be made successfully in order for your final action to be taken.


Top
 Profile  
 
PostPosted: Thu Apr 19, 2012 10:47 am 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
Robert07 wrote:
Usually with ajax I don't think of passing stuff back because that brings to mind return values. But it looks like you are trying to get your FilltheForm callback function working, yes? How do you know the information is obtained and parsed by send_one_isbn.php, did you add a print statement somewhere or examine the http response in firebug? If you see the Title, Author, etc. info coming back from the ajax call (as seen in firebug), then you should be able to add an alert statement in your FilltheForm function to see it.

However, inserting the results directly into the database inside your ajax function is actually a safer method because it means there is one less network call that needs to be made successfully in order for your final action to be taken.


Yes, I WAS trying to pass the results back. But gradually realized, perhaps, I should not do that.
I run the send_one_isbn.php separately by giving the ISBN on the url directly, and I saw the parsed results by
echo the results (on the server instead of the results passed back).
In firfox I can only see the http call with the IBN number passed.
(I do not know much about how to fully use firefox, tell me, thanks.)
So far the passing back is not successful. That is why I ask here.........should I use a return xxx as calling a function?
Otherwise how does AJAX know which results should it pass back?


Top
 Profile  
 
PostPosted: Thu Apr 19, 2012 12:05 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
Firebug is a free plugin/extension for firefox that will allow you to see what is sent and returned from ajax calls within your webpages. Once you add Firebug to your firefox install then you can right click on any webpage and select "inspect element with firebug". This will bring up a section in the bottom of the browser, and if you click on the Net tab before any ajax calls are made you will see records of them in that window when they are made. For example you can open gmail and in the Net tab you'll see every 30 seconds or so they ping the server for new email in your account.

For ajax to "pass back" any value it just needs to be echoed, like you have already setup. So the first thing to check is if you see the same thing in the Firebug Net tab (when you expand the http request and view the response tab from that call) that you do from a separate browser window where you set the ajax url with the ISBN parameter in the URL. Then you can try adding the alert in the callback function that I mentioned before. This is how you break it down and figure out where an adjustment needs to be made.

You might also want to review an article I wrote about understanding ajax at http://www.wilycode.com/the-essence-of-ajax-how-i-learned-it-in-an-hour/.


Top
 Profile  
 
PostPosted: Thu Apr 19, 2012 5:32 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
Thank you for the reply. But, which one is called the "net tab"? Do you mean the "bottom"(instead of keyboard) right to "script" and "DOM"? By next choosing XHR I saw the call out (the same as previously saw without firbug). But not
found anything back?


Strangely, I saw an error complaining cross domain call before I even called AJAX. Actually even before the onchange event I have ever called. How can I located where does it called?

Another question: where should I put this line:
<script type="text/javascript" src="../js/prototype.js"></script>
?
My understanding is anywhere is the same, since javascript can be put anywhere? But almost anywhere results some error messages. At this moment I put it at the very end of the code.


Last edited by wvoyance on Fri Apr 20, 2012 4:03 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Apr 19, 2012 6:15 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
I see that you have htaccess protection on the file you want to interact with (because I clicked on it), that would cause the behavior you are seeing where nothing is being transmitted.

As far as the Net tab, please see the attached image to see what I meant. This is gmail, which uses ajax frequently to check for new messages. I've expanded on such call and I'm showing the response from the server (I assume "noop" means there are no new messages at that time).

The javascript prototype line should be ideally in the HEAD section of the html page, but at least put it above where you expect to be able to use what is in it.

If you are seeing other http requests happening that you're not familiar with, check your source code. The javascript error panel is going to show errors from any page open since it was last cleared or the browser was started, so it's not limited to the page you are looking at. I've seen warnings and messages from gmail while I'm looking at another page, for example, because gmail is open in another browser tab.
Regards,
Robert


Attachments:
File comment: Firebug Net Tab example from gmail
firebugNetTab.PNG
firebugNetTab.PNG [ 132.92 KiB | Viewed 12632 times ]
Top
 Profile  
 
PostPosted: Thu Apr 19, 2012 9:02 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
What should I do for the .htaccess ? They are provided by the hosting site. Change the access mode of it?

Oh!! Yes, I have seen the echoed results came back (presumably it is back:). But do I still use echo for image files?

Do you know what is the corresponding command of AJAX.request for jQuery?


Last edited by wvoyance on Fri Apr 20, 2012 4:01 am, edited 1 time in total.

Top
 Profile  
 
PostPosted: Thu Apr 19, 2012 11:17 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
Hello again,
There is probably a way to make an ajax call to an htaccess protected file, but if you can remove it or put that ajax file into another directory without htaccess protection that would be easier.

What are you trying to do with that cross domain code, copy image files?

Typically you'll use json or xml for formatting responses from ajax, for passing pictures I would suggest you pass links to them instead.

Regards,
Robert


Top
 Profile  
 
PostPosted: Fri Apr 20, 2012 3:59 am 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
The conclusion is we have seen something has passing into the javascript. But which variable should I use to get the received
text? FilltheForm
var textDoc=originalRequest.responseText;
Does not seems to have the coming text.

Yes, trying to copy. There should have a special way to handle image file, since firebug screen has a special button for image.

Yes, the file format I obtained is JSON.
Actually I do not know how to parse XML format.
XML return like this:

<rsp stat="ok"><isbn oclcnum="61280830 82307052" form="BC" year="2005" lang="chi" ed="Chu ban." title="Dongjing man chi ju le bu" author="Liu Li'er." publisher="Shi bao wen hua chu ban qi ye gu fen you xian gong si" city="Taibei Shi" url="http://www.worldcat.org/oclc/61280830?referer=xid">9789571342986</isbn></rsp>

I can only get what is between <isbn ...>xxxxx</isbn> but the important data is inside the bracket.


Top
 Profile  
 
PostPosted: Fri Apr 20, 2012 11:30 am 
Offline
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
So you are seeing the Title: and Author: etc. in the response from your ajax now using the Firebug Net tab? If that's the case, try adding this in your FilltheForm function after defining textDoc:
alert(textDoc);

Does that display the same response?

I don't know where the xml data you mentioned is coming from, but you could use preg_match to get whatever you want from it, if you don't want to mess with xml attribute parsing.


Top
 Profile  
 
PostPosted: Fri Apr 20, 2012 8:15 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
Yes, there are indeed pop up showing (the same) textDoc by alert.

So, the problem is at locating the elements to be replaced.
I know there are two ways:
1. by ID
2. by a long long.......name

The problem of the second method is sometimes the list of name you think of is different from the one understand by PHP.
Is there any way, for instance by firebug or NETBeans (which I am using), they can help to locate the element?
For the first method, the problem is similar, I think this <td id="xx"> might be the place to replace, but PHP do not think so.
More important, the element is not located in a simple structure, for instance

<td class="main"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']) .
'&nbsp;' .
tep_draw_input_field('products_name[' . $languages[$i]['id'] . ']',
(isset($products_name[$languages[$i]['id']]) ?
stripslashes($products_name[$languages[$i]['id']]) :
tep_get_products_name($pInfo->products_id, $languages[$i]['id']))); ?></td>

The second part is where I want to locat, i.e. tep_draw_input_field. But it is generate by other function.

The XML came from xisbn query by
http://xisbn.worldcat.org/webservices/x ... t=xml&fl=*
(The same as JSON result except the format is replaced)
The problem is it is difficult to know the structure that PHP perceived.
What I perceived is different from what PHP perceived :(.


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 5:13 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
Now it becomes a pattern matching exercise. I'm just not clear on what you want to match. In the response text from the ajax, are you looking to put the tep_draw_input_field function call into a string variable in your FilltheForm function?


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 8:37 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Apr 17, 2012 8:24 pm
Posts: 135
The pattern matching of the returning string should be simple, I shall try it. I just want to take out the author, title, ...information to put into the products name, etc.

The OSC programs (http://www.oscommerce.com/solutions/downloads) originally ask administrator to fill the information for the products.
I was hoping to automatically fill the form by the information acquired as the name suggested,
but I am wondering whether is it possible. (Perhaps, I should insert the data directly into the database, which is another task I do not know how to accomplish yet.)
The tep_draw_input simply output a line <input type="..", value="..."..> for the html. I am not sure how to replace its value when this line is generated by a function.

If I use

document.getElementById("pd").innerHTML=textDoc;

while "pd" is

<tr>
<td class="main" valign="top"><?php echo tep_image(DIR_WS_CATALOG_LANGUAGES . $languages[$i]['directory'] . '/images/' . $languages[$i]['image'], $languages[$i]['name']); ?>&nbsp;</td>
<td class="main" id="pd"><?php echo tep_draw_textarea_field('products_description[' . $languages[$i]['id'] . ']', 'soft', '70', '15', (isset($products_description[$languages[$i]['id']]) ? stripslashes($products_description[$languages[$i]['id']]) : tep_get_products_description($pInfo->products_id, $languages[$i]['id']))); ?></td>
</tr>

then it is the entire field be replaced.
I should somehow be able to get deeper into the nested list. I read a little jQuery. It seems jQuery is good at such naming task?


Top
 Profile  
 
PostPosted: Sun Apr 22, 2012 10:14 pm 
Offline
Forum Contributor
User avatar

Joined: Tue Jun 17, 2008 1:41 pm
Posts: 113
It appears that it would be simpler to update the db directly. I would do it that way if I were you.


Top
 Profile  
 
PostPosted: Sun Aug 09, 2015 10:32 pm 
Offline
Forum Newbie

Joined: Mon Jul 27, 2015 1:49 am
Posts: 1
originally ask administrator to fill the information for the products.
ทางเข้า gclub


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: hchuchdwig and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group